View頁面,在這裏ID不能在這裏得到解析顯示一些錯誤likeMessage:未定義的變量:行& &消息:試圖讓非對象的屬性「ID」不會被解析的笨視圖控制器
<form action="<?php echo site_url('Insert_ctrl/update/'.$row->id.'');?>" method="post">
<?php
foreach ($g as $row)
{
?>
<label>ID</label>
<input type="text" name="id" value="<?php echo $row->id;?>"><br>
<label>Name</label>
<input type="text" name="dname" value="<?php echo $row->student_name;?>"><br>
這裏是我的控制器頁面
function edit($id)
{
$data['g'] ="";
$this->load->database();
$this->load->model('Inserts_model');
$data['g'] =$this->Inserts_model->select_row($id);
$this->load->view('update_view', $data);
}
這裏是我的模型
public function select_row($id)
{
$this->db->where('id', $id);
$query = $this->db->get('student');
return $query->result_object();
}
頁
這裏是另一個控制器功能更新即那張表格後得到執行
function update($id)
{
if(isset($_POST['update']))
{
$data = array
(
'student_name' => $this->input->post('dname'),
'student_email' => $this->input->post('demail'),
'student_mobile' => $this->input->post('dmobile'),
'student_address' => $this->input->post('daddress')
);
$this->Inserts_model->update($data,$id);
redirect('Insert_ctrl/index');
}
}
我們可以看到闕在模型中執行功能? – goseo
在你的控制器中echo'$ id'並檢查。 'echo $ id;退出;' –