cakephp $ this-> redirect在函数中不起作用

iwj*_*145 1 cakephp cakephp-2.3

我是新手蛋糕,我试图在保存事件后让函数重定向..它可以在其他代码中工作,例如用户,但不在事件中...

功能可以保存事件,它只需要重定向或使用SETFLASH

这是我的事件控制器添加功能的代码:

public function add() {
        if ($this->request->is('post')) {
            $this->Event->create();
            if ($this->Event->save($this->request->data)) {
                $this->Session->setFlash(__('The event has been saved'));
                $this->redirect(array('action' => 'eventmanage'));
            } else {
                $this->Session->setFlash(__('The event could not be saved. Please, contact the administrator.'));
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助都会非常感谢!

tha*_*tah 5

最可能的原因是您的应用程序在发送重定向标头之前输出了一些数据.

检查<?php标记之前是否有空格,或者在?>结束标记之后(您应该在仅php文件中删除它们),或者您的文件是否包含utf-8 BOM等.

您可以通过检查firebug或Chrome webinspector内部的响应来检查这一点