删除后,CakePHP打印模型中的信息
我想设置一条为用户打印确认信息的消息,即: “感谢您删除XYZ” 目前,我的delete()方法如下所示:删除后,CakePHP打印模型中的信息,php,cakephp,cakephp-model,Php,Cakephp,Cakephp Model,我想设置一条为用户打印确认信息的消息,即: “感谢您删除XYZ” 目前,我的delete()方法如下所示: public function delete($id) { if ($this->request->is('get')) { throw new MethodNotAllowedException(); } if ($this->Product->delete($id)) {
public function delete($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Product->delete($id)) {
echo "<pre>";
echo "id: " . $id;
print_r($this->Product->find('all',
array("condition",
array("Product.id" => $id)
)
)
);
echo "</pre>";
}
}
公共函数删除($id){
如果($this->request->is('get')){
抛出新方法NotAllowedException();
}
如果($this->Product->delete($id)){
回声“;
$product = $this->Product->find('first', array(
'conditions' => array(
'Product.id' => $id,
) ,
'fields' => array(
'Product.name'
)
));
echo“id:”.$id;
$product = $this->Product->find('first', array(
'conditions' => array(
'Product.id' => $id,
) ,
'fields' => array(
'Product.name'
)
));
打印($this->Product->find('all'),
数组(“条件”,
数组(“Product.id”=>$id)
)
)
);
回声“;
$product = $this->Product->find('first', array(
'conditions' => array(
'Product.id' => $id,
) ,
'fields' => array(
'Product.name'
)
));
}
}
但是,print_r()语句显示了所有产品,并且缺少了一个delete,我认为这是正确的行为。如何获取刚刚删除的项目的名称?假设您的
$id
不是空的,其中包含一些产品
所以您可以使用如下查询
因此,在$product['product']['name']
中,您将获得要删除的当前产品名称
如果我能为您提供更多帮助,请告诉我。通常,在cakephp中,我使用debug($thing\u to\u output\u debuging);(不打印)