2013-05-04 73 views
0

我想设置一个信息,即打印用户的确认,即:CakePHP的打印信息删除后

“谢谢你删除XYZ”。

目前我的delete()方法是这样的:

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>"; 
     } 
    } 

然而,的print_r()语句显示所有产品,以及一个删除丢失 - 我假设是正确的行为。我怎样才能得到刚删除的项目的名称?

+0

Usualy,在cakephp,我使用调试($ thing_to_output_debugin G); (而不是print_r) – 2015-04-28 11:34:17

回答

2

从假设你$id是不是其中包含一些产品

,所以你可以使用查询像下面

$product = $this->Product->find('first', array(
     'conditions' => array(
      'Product.id' => $id, 
     ) , 
     'fields' => array(
      'Product.name' 
     ) 
    )); 

空的,所以在$product['Product']['name']你会得到当前的产品名称是您要删除

请让我知道,如果我可以帮助你更多..

+0

是,ID始终有效。这工作。谢谢。 – Tamas 2013-05-04 04:02:29

+0

很高兴帮助你.. – liyakat 2013-05-04 04:04:23