简体   繁体   English

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

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

I'm new to CakePHP. 我是CakePHP的新手。 I'm just testing how it works. 我只是在测试它的工作方式。 I use other frameworks in PHP. 我在PHP中使用其他框架。 Here in CakePHP 3.6 freshly installed. 这里是在CakePHP 3.6中新安装的。 I'm following CakePHP's blog tutorial. 我正在关注CakePHP的博客教程。 My code is: 我的代码是:

 $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);

The problem is while redirecting to another action. 问题是重定向到另一个动作时。 When I comment line return $this->redirect(['action' => 'index']); 当我注释行时, return $this->redirect(['action' => 'index']); it works else it throws following error. 它可以正常工作,否则会引发以下错误。

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]

In your appController change 在您的appController中更改

$this->loadComponent('RequestHandler');

to

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

(I know, this is not a great answer. If I have time I will expand it) (我知道,这不是一个很好的答案。如果有时间,我会扩展它)

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

相关问题 PHP | Codeigniter重定向| 无法修改标题信息 - PHP | Codeigniter Redirect | Cannot modify header information 尝试重定向时看到“无法修改标题信息”错误 - Seeing “Cannot modify header information” error when attempting to redirect 尝试重定向页面时无法修改标题信息错误 - Cannot modify header information error when trying to redirect page 脚本中有多个PHP“header(url)”,“无法修改标题信息”错误 - Multiple PHP “header(url)” in script, “Cannot modify header information” Error 重定向头信息出错 - error on header information on redirect FileMaker API for PHP登录页面错误-无法修改标题信息 - FileMaker API for PHP login page error - Cannot modify header information PHP“无法修改标题信息”错误不会消失。 - PHP “Cannot modify header information” error wont go away. 无法修改 header 信息 - 标头已发送 - PHP MVC:从一个 controller 重定向到另一个 Z5904C103F2C030 - Cannot modify header information - headers already sent - PHP MVC : Redirect from one controller to another controller 错误“无法修改标题信息-标题已经发送”。成功提交表单后如何重定向 - “Cannot modify header information - headers already sent by” error.How to redirect upon successful submission of the form PHP重定向返回“无法修改标头信息” - PHP redirection returns “Cannot modify header information”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM