[英]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.