【发布时间】:2011-06-22 15:55:42
【问题描述】:
这是错误:
Warning (2): Cannot modify header information - headers already sent by (output started at /usr/share/php/cake/basics.php:111) [CORE/cake/libs/controller/controller.php, line 640]
$status = "Location: http://mydomain.com/blog/index"
header - [internal], line ??
Controller::header() - CORE/cake/libs/controller/controller.php, line 640
Controller::redirect() - CORE/cake/libs/controller/controller.php, line 621
PostsController::add() - APP/controllers/posts_controller.php, line 25
Object::dispatchMethod() - CORE/cake/libs/object.php, line 115
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 227
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
[main] - APP/webroot/index.php, line 88
这是posts_controller.php的代码:
function add() {
if (!empty($this->data)) {
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->Session->setFlash(__('Post saved!!', true));
$this->redirect(array('action'=>'index')); // line 25
} else {
}
}
$tags = $this->Post->Tag->find('list');
$statuses = $this->Post->Status->find('list');
$this->set(compact('tags', 'statuses'));
}
这是第 111 行:
echo "\n<pre class=\"cake-debug\">\n";
debug_print_backtrace() 在basics.php core cake 文件中的输出:
http://pastebin.com/fBFrkYsP
我已经浏览了我编辑的所有文件(而不是我刚刚烘焙的文件),并且我在 php 括号 () 之外没有任何空格。我使用了这个脚本:Find all files with Blank or WS at BOF or EOF。
我的文本编辑器设置为 UTF-8。基本上,当我注释掉第 25 行(上面标有注释)时,问题就消失了。但我应该能够使用重定向...谁能指出我正确的方向?
编辑: 在上面的 111 处添加了行;编辑 2:添加了 debug_print_backtrace() 的输出
【问题讨论】:
-
我面前没有蛋糕芯,但是第640行是什么? (和第 111 行)
-
@lollercoaster 真的很快 - 请将代码粘贴到
/usr/share/php/cake/basics.php附近的第 111 行??? -
确保您的 UTF-8 文件中没有字节顺序标记 (BOM)。将它们保存为不带 BOM 的 UTF-8。
-
@lollercoaster:如果你愿意,你可以找到更合适的精确副本。但是其中大约有 157238 个,没有理由让这个问题保持开放。几千人在向您发送标头之前犯了输出 html 标签的错误。 (还有the manual mentions exactly那个。)
标签: php cakephp http-headers byte-order-mark