1

这是我的代码

    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

如何解决?

4

1 回答 1

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');
        }
    }
}
于 2011-10-31T11:40:32.137 回答