使用CakePHP 3.4,PHP 7.0.
我正在尝试使用一个非常简单的控制器方法来输出一些JSON.它输出"无法修改标题...".
public function test() {
$this->autoRender = false;
echo json_encode(['method' => __METHOD__, 'class' => get_called_class()]);
}
Run Code Online (Sandbox Code Playgroud)
浏览器输出
{"method":"App\\Controller\\SomeController::test", "class":"App\\Controller\\SomeController"}
Warning (512): Unable to emit headers. Headers sent in file=...
Warning (2): Cannot modify header information - headers already sent by (output started at ...)
Warning (2): Cannot modify header information - headers already sent by (output started at ...)
Run Code Online (Sandbox Code Playgroud)
我完全理解为什么PHP抱怨这个.问题是为什么CakePHP会抱怨我该怎么办?
应该注意的是,CakePHP 2.x允许这样做.