CakePHP没有重定向,没有显示错误

时间:2013-08-14 22:44:44

标签: php cakephp

删除一些数据后,我在重定向页面时遇到了一些麻烦。它以前工作过,我已经添加了很多,所以我不知道是什么导致了这个问题。

这是通过烘焙生成的功能。奇怪的部分是功能正常工作并正确删除记录,但它只是停留在空白页面上。

public function delete($id = null) {
    $this->Visit->id = $id;
    if (!$this->Visit->exists()) {
        throw new NotFoundException(__('Invalid visit'));
    }
    $this->request->onlyAllow('post', 'delete');
    if ($this->Visit->delete()) {
        $this->Session->setFlash(__('Visit deleted'));
        $this->redirect(array('action' => 'index'));
    }
    $this->Session->setFlash(__('Visit was not deleted'));
    $this->redirect(array('action' => 'index'));
}

但是,当我将其更改为仅重定向函数调用时,它可以正常工作。删除有些东西,我似乎无法弄清楚发生了什么。

 public function delete($id = null) {
    $this->Visit->id = $id;
    if (!$this->Visit->exists()) {
        throw new NotFoundException(__('Invalid visit'));
    }

    $this->Session->setFlash(__('Visit deleted'));
    $this->redirect(array('action' => 'index'));

}

我能找到什么?我的模型中没有关于重定向的任何内容

1 个答案:

答案 0 :(得分:0)

我认为你必须添加控制器:

// http://book.cakephp.org/2.0/en/controllers.html

$this->redirect(array('controller' => '<YOUR CONTROLLER NAME>', 'action' => 'index'));

如果要重定向到引用页面

,可以尝试这样做
$this->redirect($this->referer());

对于未来的工作:你说“只是停留在空白页面上”。你的调试级别是多少?如果它处于开发模式,重定向不会自动完成,但是有一个链接continue to redirect(文本可能类似,不记得)。你可以看到目标是否可以到达,例如控制器动作是否存在。

相关问题