【发布时间】:2015-10-31 18:01:44
【问题描述】:
我在使用 cakephp 2.x 进行重定向时遇到问题。
当我执行重定向下方的功能时,它可以完美运行:
public function test() {
$this->redirect(array('controller' => 'pages','action' => 'index'));
}
但是当我对数据库执行一个事务(添加、修改和删除)时,该函数将我重定向到一个空白页面:
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'));
}
重定向不起作用。 谢谢你帮助我
【问题讨论】:
-
你试过重定向到不同的控制器吗?
-
“空白页”是什么意思?您的浏览器中的 URL 是
/pages/index还是其他的?您是否检查过 CakePHP 文件夹中的错误日志文件?您是否在浏览器中使用 webdeveloper 工具检查过 HTTP 响应代码(什么错误代码,例如 404/500)?空白页面可能是由重定向的目的地(页面控制器中的索引操作)引起的吗?...