如何解决Codeigniter 4 软删除仍在删除数据库记录
我在使用 CodeIgniter 4 软删除时遇到问题。 我在模型中设置了 $useSoftDelete = true;但是每当我删除一条记录时,delete 方法总是将它从我的表中清除。
这是我模型中的代码:
// Dates
protected $useTimestamps = true;
protected $useSoftDelete = true;
protected $dateFormat = 'datetime';
protected $createdField = 'cust_created_at';
protected $updatedField = 'cust_updated_at';
protected $deletedField = 'cust_deleted_at';
public function delete($id = '')
{
$customer = $this->customerModel->find($id);
if (isset($customer)) {
$this->customerModel->delete($id);
session()->setFlashdata('success',"Customer $customer->cust_name successfully deleted.");
return redirect()->to(site_url('customer'));
} else {
session()->setFlashdata('errors',["Cannot find customer ID $id."]);
return redirect()->to(site_url('customer'));
}
}
我错过了任何代码吗? 提前致谢。
解决方法
输入错误protected $useSoftDelete = true;
。
应该是protected $useSoftDeletes = true;
参考: https://codeigniter4.github.io/userguide/models/model.html#configuring-your-model
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。