2011-10-29 69 views
1

這是我的代碼isAjax()在CakePHP 2.0上已被棄用。用什麼方法替代那個方法?

function add() { 
    if(!empty($this->data)) { 
     if($this->Post->save($this->data)) { 
      if($this->RequestHandler->isAjax()){ //isAjax method is deprecated. 
       //Handle Ajax 
       $this->render('notif','ajax'); 
      } else { 
       $this->Session->setFlash('Add successfully'); 
       $this->redirect(array('action'=>'index'));      
      } 
     } 
     else { 
      $this->Session->setFlash('Add failded please try again'); 
     } 
    } 
} 

在這裏,我讀到方法已http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html?highlight=isajax

如何解決呢?

回答

5

它說CakeRequest現在負責。你可以在這裏找到相應的段落:http://book.cakephp.org/2.0/en/controllers/request-response.html#inspecting-the-request

function add() { 
    if(!empty($this->request->data)) { 
     if($this->Post->save($this->request->data)) { 
      if($this->request->is('ajax')){ 
       //Handle Ajax 
       $this->render('notif','ajax'); 
      } else { 
       $this->Session->setFlash('Add successfully'); 
       $this->redirect(array('action'=>'index'));      
      } 
     } 
     else { 
      $this->Session->setFlash('Add failded please try again'); 
     } 
    } 
} 
相關問題