我有一个奇怪的问题,由此我看到了下面的PHP警告:CakePHP 3 - 由于内容长度而显示警告?
Warning (512): Unable to emit headers. Headers sent in file=/vendor/cakephp/cakephp/src/Error/Debugger.php line=921 [CORE/src/Http/ResponseEmitter.php, line 48]
Code Context
Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 48
Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
[main] - ROOT/webroot/index.php, line 37
Warning (2): Cannot modify header information - headers already sent by (output started at /vendor/cakephp/cakephp/src/Error/Debugger.php:921) [CORE/src/Http/ResponseEmitter.php, line 148]
Code Context
header - [internal], line ??
Cake\Http\ResponseEmitter::emitStatusLine() - CORE/src/Http/ResponseEmitter.php, line 148
Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 54
Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
[main] - ROOT/webroot/index.php, line 37
Warning (2): Cannot modify header information - headers already sent by (output started at /vendor/cakephp/cakephp/src/Error/Debugger.php:921) [CORE/src/Http/ResponseEmitter.php, line 181]
Code Context
header - [internal], line ??
Cake\Http\ResponseEmitter::emitHeaders() - CORE/src/Http/ResponseEmitter.php, line 181
Cake\Http\ResponseEmitter::emit() - CORE/src/Http/ResponseEmitter.php, line 55
Cake\Http\Server::emit() - CORE/src/Http/Server.php, line 105
[main] - ROOT/webroot/index.php, line 37
我在开发模式('DEBUG', true
在app/config.php
)是。如果我将其设置为false
,则警告消失,如预期。
错误是由该控制器方法始发:
public function ajaxSubstances()
{
$this->autoRender = false;
$SubstanceModel = new SubstanceModel;
$data = ['data' => $SubstanceModel->getSubstances()];
debug($data);
}
我不明白的是,如果我的$data
数组只包含,说20元,没有警告显示。随着我逐渐添加更多元素,一旦有一定数量的记录(大约> = 30个元素),它会始终显示警告。
要检查它不是源数据(来自getSubstances()
)我硬编码了一个$data
数组,但同样的事情发生。
此方法将被用来作为Ajax响应和被馈送到数据表。不幸的是,如果输出警告,DataTables将显示错误,因为它不是有效的响应。
我无法将debug
更改为false
,因为我需要在我的其他开发中使用该功能。我想知道为什么这可能会发生呢?
我不知道为什么它的尝试,因为头型不被任何地方的代码改为“发射头” - 它的使用debug()
输出的一切,我也试过var_dump()
但输出仍然是相同的text/html
内容类型。
感谢一如既往对您有所帮助。我需要输出的数据需要是JSON提要。我配置为https://book.cakephp.org/3.0/en/views/json-and-xml-views.html描述这似乎已经帮助JSON的意见 - 内容类型头被适当地设置,我可以输出任何数量的数据没有问题,所以它似乎到目前为止! – Andy