我在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。