“ID”不会被解析的笨视图控制器

问题描述:

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'); 
        } 
     } 
+0

我们可以看到阙在模型中执行功能? – goseo

+0

在你的控制器中echo'$ id'并检查。 'echo $ id;退出;' –

每当你尝试从数据库中获得单个记录,那么你应该使用row(),而不是result()

public function select_row($id) 
{ 
    $this->db->where('id', $id); 
    $query = $this->db->get('student'); 
    return $query->row(); //use row() instead of result 
} 

你的方法名是edit和您提交update方法

<form action="<?php echo site_url('Insert_ctrl/edit/'.$g[0]->id.'');?>" method="post"> 

的形式,如果你是路过idinput,那么你并不需要与URL

送你应该尝试与此$this->uri->segment(3);

+0

请通过上面编辑的代码 –

+0

@jibinkj我已经更新我的回答 –

+0

@jibinkj你可以通过print_r()来显示你的'$ g' foreach()' –

,如果你要查询单行,那么你最好使用row_array()

return $query->row_array(); 

,然后你就可以访问数组的索引,如:

echo $row['id']; 
+0

不,返回$ query-> result_object();在模型页 –