【问题标题】:cakephp debug messages still displaying with debug set to 0 using ajax and jsoncakephp 调试消息仍然显示,使用 ajax 和 json 将调试设置为 0
【发布时间】:2012-10-02 21:13:45
【问题描述】:

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);

    }

【问题讨论】:

  • 您的控制器中是否有任何 beforeFilter() 覆盖了 app_controller 中的 beforeFilter() ?
  • 你的调试()在哪里?粘贴代码?

标签: cakephp


【解决方案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;
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多