使用ajax和json将cakephp调试消息显示为调试设置为0。我无法将autorender设置为false,因为我需要设置标头以发送json。
json.ctp
<?php
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
header('Content-Type: application/json');
header("X-JSON: ".$json);
echo $json;
?>
控制器
function index(){
if (!empty($this->data)){
// Handle all JSON requests here
if ($this->RequestHandler->isAjax()){
$domain = $this->data['domain'];
$results = $this->Domain->google_api($domain,$seo_action);
$json = json_encode($results);
$this->set(compact('json'));
$this->render('json','ajax');
} else {
$domain = $this->data['Results']['domain'];
}
}
$this->set(compact('domain'));
$this->layout = 'front_end';
}
app_controller
function beforeFilter(){
if ($this->RequestHandler->isAjax()) Configure::write('debug', 0);
}
答案 0 :(得分:1)
您可以将Configure::write('debug', 0);
作为第一行添加到json.ctp
。所以它会:
<?php
Configure::write('debug', 0);
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
header('Content-Type: application/json');
header("X-JSON: ".$json);
echo $json;
?>