在 Cakephp 应用程序中删除数据时出现以下错误:
Undefined index: Image [CORE/cake/libs/model/model.php, line 1477]
Model::updateCounterCache() - CORE/cake/libs/model/model.php, line 1477
Model::delete() - CORE/cake/libs/model/model.php, line 1842
ImagesController::delete() - APP/controllers/images_controller.php, line 67
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 86
这是我的代码,它得到了这个错误:
$this->Image->delete($image_id);
我已经确认 $image_id 不为空并且是正确的,还确认了此特定行触发了错误。我在 images_controller 里面。我正在使用 Cakephp 1.3。
这是我的图像模型代码:
class Image extends AppModel {
var $name = 'Image';
var $belongsTo = "User";
function afterFind($results)
{
/*some custom afterfind work here */
}
}
正在从数据库中删除图像,但我不断收到此错误。
======================================== 编辑
函数的完整代码:
function delete() {
$this->checkAuth();
$user_id = $user_id = $this->Auth->user('id');
if(!empty($this->data))
{
$image_id = $this->data['Image']['id'];
$image = $this->Image->find("first", array("conditions"=>array("Image.id"=>$image_id)));
if($image) {
if($image['Image']['user_id']==$user_id){
$this->Image2->delete_image($image['Image']['image_path'],"upload");
//echo "image id:".$image_id;
$this->Image->delete(intval($image_id));
$this->set("success","1");
$this->set("msg","Image deleted successfully.");
}
else {
$this->set("success","0");
$this->set("msg","You do not have permission to delete this image.");
}
}
else {
$this->set("success","0");
$this->set("msg","Cannot find image.");
}
}
else
{
$this->set("success","0");
$this->set("msg","No data posted");
}
}
当我们从中输出 json 时,视图中没有任何内容。