CakePHP重定向到空白页面

时间:2015-10-31 18:01:44

标签: php cakephp redirect

我遇到了使用cakephp 2.x进行重定向的问题。

当我执行重定向下方的功能时,它可以完美地运行:

public function test() {
    $this->redirect(array('controller' => 'pages','action' => 'index'));
}

但是当我用数据库执行trasaction(添加,修改和删除)时,该函数会将我重定向到空白页面:

public function delete($id = null) {
    $this->Post->id = $id;
    if (!$this->Post->exists()) {
        throw new NotFoundException(__('Invalid post'));
    }
    if ($this->Post->deleteAll(array('Post.id' => $id), false)) {
        $this->Session->setFlash(__(" success."), 'flash', array('class' => 'alert alert-success'));
    } else {
        $this->Session->setFlash(__("error."), 'flash', array('class' => 'alert alert-danger'));
    }
    $this->redirect(array('controller' => 'pages','action' => 'index'));
}

重定向不起作用。 谢谢你的帮助

2 个答案:

答案 0 :(得分:0)

您是否检查过调试1或2,是否显示某种类型的错误。另外,为什么使用deleteAll删除单个记录,请使用delete方法而不是deleteAll。

$this->Post->delete($id);

答案 1 :(得分:0)

请在重定向行动之前检查是否有任何打印,即使它是一个可以防止重定向的空间。

相关问题