我一直在努力,并没有得到一个合适的解决方案。我想要做的是我有一个控制器的功能,从模型中获取数据。 这是我的控制器功能:如何在控制器和视图之间建立连接?
function index() {
$data['results1'] = $this->RetrieveData_model->GetData();
$this->load->view('ViewData',$data);
}
我想访问$数据[“结果1”]变量在我EditView中自动填补fields.this是我的看法:
<div id="container">
<?php echo form_open('insert_ctrl/updateData/'); ?>
<h1>Update Data Into Database Using CodeIgniter</h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data updated successfully</h3></CENTER><br>
<?php } ?>
<?php echo form_label('Student Name :'); ?> <?php echo form_error('dname'); ?><br />
<?php echo form_input(array('id' => 'dname', 'name' => 'dname', 'value' => $results1[0]->Student_Name)); ?><br />
<?php echo form_label('Student Email :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'name' => 'demail', 'value' => $results1[0]->Student_Email)); ?><br />
<?php echo form_label('Student Mobile No. :'); ?> <?php echo form_error('dmobile'); ?><br />
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile', 'placeholder' => '10 Digit Mobile No.', 'value' => $results[0]->Student_Mobile)); ?><br />
<?php echo form_label('Student Address :'); ?> <?php echo form_error('daddress'); ?><br />
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress','value' => $results1[0]->Student_Address)); ?><br />
<?php echo form_hidden(array('id' => 'studentId', 'name' => 'studentId','value' => $results1[0]->Student_id)); ?><br />
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">
</div>
<button type="button" onclick="window.location='<?php echo base_url();?>ViewData_ctrl/index'">
View data Record
</button>
</div>
当我访问的“RESULT1”鉴于这是给错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: results1
Filename: views/EditView.php
Line Number: 16
Backtrace:
File: D:\dev\htdocs\CI2\application\views\EditView.php
Line: 16
Function: _error_handler
File: D:\dev\htdocs\CI2\application\controllers\insert_ctrl.php
Line: 104
Function: view
File: D:\dev\htdocs\CI2\index.php
Line: 292
Function: require_once
请帮助我如何解决这个,因为我是新来的Codeignitor ..
可以请你告诉我,在你的控制器显示值不? – vaibhav
检查这个var_dump($ data);在你的控制器中 –