У меня в приложении есть запрос ajax, который возвращает объект json:
public function getCustomerTransactions($customerid = null)
{
$this->viewBuilder()->setLayout(false);
$this->autoRender = false;
$selectedCustomerCompany = $this->request->getData('customer');
$selectedCustomer = TableRegistry::get('Customers')->find('all', [
'conditions' => ['Customers.company LIKE '=> $selectedCustomerCompany]
])->first();
$customerTransactions = TableRegistry::get('Transactions')->find('all', [
'conditions' => ['customer_id '=> $selectedCustomer->id, 'transaction_type_id ' => 1, 'invoice_id IS NULL']//,
]);
echo json_encode($customerTransactions);
}
Но вместо 19 transactions
он возвращает 11, а затем это сообщение (я вижу его на вкладке сети):
Предупреждение (512): невозможно выдать заголовки.Заголовки отправляются в файле = / var / www / vhosts / domain / public_html / demo / app / src / Controller / InvoicesController.php строка = 508 [ CORE / src / Http / ResponseEmitter.php , строка 48 ] Контекст кода
0000BB">
<p>style="color: #007700">if (
0000BB">Configure::read
007700">('debug')) {
class = "выделение кода">
0000BB"> trigger_error
<p>style="color: #007700">(
0000BB">$message, E_USER_WARNING);
<p>style="color:</p>
007700">} else {
нет; "> $ response = object (Cake \ Http \ Response) {
'status' => (int) 200, 'contentType' => 'text / html', 'headers' => ['Content-Type' => [[достигнута максимальная глубина]]], 'file' => null, 'fileRange' => [], 'cookies' => объект (Cake \ Http \ Cookie \ CookieCollection) {}, 'cacheDirectives' => [], 'body' => ''
} $ maxBufferLength = (int) 8192 $ file = '/var/www/vhosts/domain/public_html/demo/app/src/Controller/InvoicesController.php' $ line = (int) 508 $ message = 'Невозможно выдать заголовкиЗаголовки отправляются в файле = / var / www / vhosts / domain / public_html / demo / app / src / Controller / InvoicesController.php line = 508'Cake \ Http \ ResponseEmitter :: emit () - CORE / src / Http / ResponseEmitter.php, строка 48 Cake \ Http \ Server :: emit () - CORE / src / Http / Server.php, строка 141
Итак, я получаю эту ошибку javascript:
Uncaught SyntaxError: неожиданный токен <в JSON в позиции 6922 </p>
, потому что в HTML-коде естьответ.
Я попытался установить параметр глубины в json_encode
, но получил те же результаты.
ОБНОВЛЕНИЕ
Я закончил с использованием:
if($this->request->is('ajax')){
Configure::write('debug', 0);
}
В контроллере.Но так ли это?