我正在使用自定义数据源来使用webservice。 创建,读取和更新工作正常但删除不起作用。自定义删除方法不会调用自定义数据源
这是我的代码调用我的控制器中的删除方法。
public function delete($id){
$this->autoRender = false;
debug($this->Article->delete($id));
}
这里的代码在我的数据源
public function delete(Model $Model, $id = null) {
echo "Display a message if this method is called";
$json = $this->Http->post(CakeSession::read('Site.url') . '/webservice/delete/', array(
'id' => $id,
'apiKey' => $this->config['apiKey'],
'model' => $Model->name
));
$res = json_decode($json, true);
if (is_null($res)) {
$error = json_last_error();
throw new CakeException($error);
}
return true;
}
但是,当我想删除某个项目时,debug();
显示false
。 我没有其他显示。 我不明白为什么我的删除方法没有正确调用。 我的代码有什么问题吗?
感谢
数据源代码取自手册,它应该工作正常。你能向我们展示'debug($ res)'的输出吗? – 2013-05-09 17:03:11
我在核心类中发掘,我发现为什么我的delete()没有被调用。实际上在delete方法触发Model.php上的_findCount()之前被调用。并且有一个'if(!method_exists($ db,'calculate')||!method_exists($ db,'expression')){return false;}'。 在我的数据源类中,我只有方法calculate()而不是表达式()。所以我实现了这个函数,现在它正在工作 – guillaume 2013-05-09 17:53:30