簡體   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