繁体   English   中英

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

[英]Cake php redirect error [Can not modify header information]

我是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]

在您的appController中更改

$this->loadComponent('RequestHandler');

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM