UPDATE数据预填充更新形式:从数据库
如果,在视图中,我<?php echo $customer->first_name; ?>
它正确地输出第一名。
在相同的视图文件'value' => set_value($customer->first_name)
什么都不输出。
我在做笨3.一个“客户” CRUD应用程序,我有一个更新形式,我想对应的客户数据,以预填充,已经在他的数据库存在。
的模型看起来像这样:
class Customer extends CI_Model {
/*Lots
of
code*/
public function getAllCustomers($customer_id) {
$query = $this->db->get_where('customers', array('id' => $customer_id));
if ($query->num_rows() > 0) {
return $query->row();
}
}
}
控制器看起来像这样:
class Home extends CI_Controller {
/*Lots
of
code*/
public function edit($customer_id){
$this->load->model('Customer');
$customer = $this->Customer->getAllCustomers($customer_id);
$this->load->view('update', ['customer'=>$customer]);
}
}
在视图文件(update.php)我有:
<?php echo form_input('first_name', '', [
'type' => 'text',
'id' => 'first_name',
'class' => 'form-control',
'value' => set_value($customer->first_name),
'placeholder' => 'First name',
]);
?>
的客户的first_name,尽管存在于名为“first_name”的数据库列中并未预先填充表单。
这是为什么?
'消息:试图让行19'线19个非对象的属性是'“值” => SET_VALUE( $ customer-> first_name),' –
可能不是它的'stdobject'它的一个数组尝试访问这个名字,像这样:$ customer ['first_name']' –
'$ customer ['first_name']'也不起作用。 .. –