【发布时间】:2021-05-08 10:26:40
【问题描述】:
我正在制作 CRUD,上传文件(图像),但是当我想使用取消链接删除文件时出现错误,如下所示。
Codeigniter4 错误:调用未定义的方法 CodeIgniter\Database\MySQLi\Builder:: find()
这是我用来尝试删除图像文件的代码。从控制器连接到模型。
The controller:
public function delete()
{
$model = new Datatablesmodal();
$id = $this->request->getPost('product_id');
$model->deleteProduct($id);
return redirect()->to('/modalboot');
}
The modal:
public function deleteProduct($id)
{
$foto=$this->db->table("formulir_pendaftaran")->find(array('product_id' => $id)); (line 1)
unlink('/pasfoto/'.$foto['pas_foto']); (line 2)
$this->db->table('formulir_pendaftaran')->delete(array('product_id' => $id));
return $query;
}
表的 id 是 product_id,如果我删除了第 1 行和第 2 行,我可以从表中删除数据,但不是图像文件,它仍在我的目录中,如果我使用第 1 行和第 2 行删除文件,我可以'不是因为有错误。
【问题讨论】:
-
错误告诉你
find方法不存在。我建议查看 CodeIgniter 文档以了解获取行的正确方法。
标签: php codeigniter codeigniter-4 unlink