大家好,这是我的更新记录功能的摘录
public function updateRecord()
{
helper(['form', 'url']);
$model = new EmployeeModel();
$id = $this->request->getVar('emp_id');
echo $id;
$data = [
'emp_fname' => $this->request->getVar('emp_fname'),
'emp_lname' => $this->request->getVar('emp_lname'),
'emp_mname' => $this->request->getVar('emp_mname'),
'emp_status' => $this->request->getVar('emp_status'),
'emp_position' => $this->request->getVar('emp_position'),
];
$save = $model->update($id, $data);
return redirect()->to(base_url('display'));
}
答案 0 :(得分:1)
在您的模型中,将 primaryKey 配置选项更改为您的自定义主键名称:
受保护的 $primaryKey = 'emp_id';
https://codeigniter4.github.io/userguide/models/model.html#models
答案 1 :(得分:0)
我解决了这个问题,看来在数据库上使用自定义ID不适用于CI4中的查询语句。
我在数据库本身中将emp_id更改为id,它解决了该问题。