[英]How to update input field values in codeigniter
I am a beginner in Codeigniter and using version 3 I am performing update operation so I have store data and now I have created a separate form for update and want to set this form inputs values that are stored in databases我是 Codeigniter 的初学者,正在使用版本 3 我正在执行更新操作,所以我有存储数据,现在我已经创建了一个单独的更新表单,并希望设置此表单输入存储在数据库中的值
My View (update.php)我的观点 (update.php)
```<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<?php echo form_input(['name'=>'title', 'placeholder'=>'Enter title',
'class'=>'form-control col- md-5',
'value'=>set_value('title','$post->title')]);?>
</div>```
My COntroller我的控制器
public function update($id)
{
$this->load->model('queries');
$postt=$this->queries->getSinglePosts($id);
$post=$postt->title;
$this->load->view('update',['post'=>$post]);
}
My Model我的模特
public function getSinglePosts($id) { $query=$this->db->get_where('tbl_posts',array('id'=>$id)); public function getSinglePosts($id) { $query=$this->db->get_where('tbl_posts',array('id'=>$id));
if ($query->num_rows() >0 ) {
return $query->row();
}
}
Because you've used set_value('title','$post->title')]);
因为你用过
set_value('title','$post->title')]);
in your view file, I think you should remove this line from your controller $post=$postt->title;
在您的视图文件中,我认为您应该从控制器中删除这一行
$post=$postt->title;
and you should pass the whole of $postt
variable to your view (make sure that the $postt
is not an array of objects).并且您应该将整个
$postt
变量传递给您的视图(确保$postt
不是对象数组)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.