0

cakephp 调试消息仍然显示,使用 ajax 和 json 将调试设置为 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);

    }
4

1 回答 1

1

您可以将Configure::write('debug', 0);as 第一行放到您的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;
?>
于 2012-10-03T05:38:45.353 回答