函数错误的参数太少(更新数据)CodeIgniter
too few arguments for function error (updating data) CodeIgniter
我的更新代码出现错误。功能参数太少。
我在网上搜索了一下,我不确定我是否传递了 id。
控制器:
public function update()
{
if($this->Admin_model->update($this->input->post(null, true))){
$this->session->set_flashdata('flash_msg', ['message' => 'User updated successfully', 'color' => 'green']);
} else {
$this->session->set_flashdata('flash_msg', ['message' => 'Error updating user.', 'color' => 'red']);
}
$this->admin_redirect('cms');
}
型号:
public function update($id, $data)
{
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
return $this->db->update($this->table, $data);
}
正如@WILLIAM 在评论中所述,您的 update(...)
方法需要 2 个参数,但传递了一个参数。
将您的 update(...)
方法更改为:
public function update($data)
{
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
$this->db->where('id', $data['id']);
return $this->db->update($this->table, $data);
}
这假设 'id'
是您 HTML form.i 的一部分。e:
<input type="hidden" name="id" value="<?php echo $id ?>">
您需要在控制器代码中使用 2 个参数调用您的模型 update 函数,但您似乎只使用一个参数 $data 值来调用它。
在下面的代码中:
if($this->Admin_model->update(**$this->input->post(null, true)**))
它应该使用 2 个值调用,第一个应该是标识您要在模型中更新的记录的 ID,另一个应该是将在该记录中更新的数据。
希望!你得到了答案。
我的更新代码出现错误。功能参数太少。 我在网上搜索了一下,我不确定我是否传递了 id。
控制器:
public function update()
{
if($this->Admin_model->update($this->input->post(null, true))){
$this->session->set_flashdata('flash_msg', ['message' => 'User updated successfully', 'color' => 'green']);
} else {
$this->session->set_flashdata('flash_msg', ['message' => 'Error updating user.', 'color' => 'red']);
}
$this->admin_redirect('cms');
}
型号:
public function update($id, $data)
{
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
return $this->db->update($this->table, $data);
}
正如@WILLIAM 在评论中所述,您的 update(...)
方法需要 2 个参数,但传递了一个参数。
将您的 update(...)
方法更改为:
public function update($data)
{
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
$this->db->where('id', $data['id']);
return $this->db->update($this->table, $data);
}
这假设 'id'
是您 HTML form.i 的一部分。e:
<input type="hidden" name="id" value="<?php echo $id ?>">
您需要在控制器代码中使用 2 个参数调用您的模型 update 函数,但您似乎只使用一个参数 $data 值来调用它。
在下面的代码中:
if($this->Admin_model->update(**$this->input->post(null, true)**))
它应该使用 2 个值调用,第一个应该是标识您要在模型中更新的记录的 ID,另一个应该是将在该记录中更新的数据。
希望!你得到了答案。