我一直在努力,並沒有得到一個合適的解決方案。我想要做的是我有一個控制器的功能,從模型中獲取數據。 這是我的控制器功能:如何在控制器和視圖之間建立連接?
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);在你的控制器中 –