isAjax () является устаревшим методом в CakePHP 2.0. Какой метод заменит этот метод? - PullRequest
1 голос
/ 29 октября 2011

Это мой код

    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

Как это исправить?

1 Ответ

5 голосов
/ 31 октября 2011

В нем говорится, что 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');
        }
    }
}
...