Cake php重定向错误[无法修改标题信息]

时间:2018-04-26 14:13:29

标签: php cakephp-3.0

我是CakePHP的新手。我只是测试它是如何工作的。我在PHP中使用其他框架。这里在CakePHP 3.6中新安装。我正在关注CakePHP的博客教程。我的代码是:

 $article = $this->Articles->newEntity();
            if ($this->request->is('post')) {
                // Prior to 3.4.0 $this->request->data() was used.
                $article = $this->Articles->patchEntity($article, $this->request->getData());
                if ($this->Articles->save($article)) {
                    $this->Flash->success(__('Your article has been saved.'));
                   return $this->redirect(['action' => 'index']);
                }
                else {
                    $this->Flash->error(__('Unable to add your article.'));
                }

            }
            $this->set('article', $article);

问题在于重定向到另一个动作。当我对第return $this->redirect(['action' => 'index']);行进行评论时,它会发挥其他错误。

Warning (512): Unable to emit headers. Headers sent in file=C:\Users\Dipti\blog\vendor\cakephp\cakephp\src\Error\Debugger.php line=853 [CORE\src\Http\ResponseEmitter.php, line 48] Warning (2): Cannot modify header information - headers already sent by (output started at C:\Users\Dipti\blog\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 148]

1 个答案:

答案 0 :(得分:3)

在你的appController更改

$this->loadComponent('RequestHandler');

$this->loadComponent('RequestHandler', [
    'enableBeforeRedirect' => false
]);

(我知道,这不是一个很好的答案。如果我有时间,我会扩展它)