这是我的代码
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
如何解决这个问题?
答案 0 :(得分: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');
}
}
}