Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony1 如何防止调试工具栏出现在prod环境中_Symfony1 - Fatal编程技术网

Symfony1 如何防止调试工具栏出现在prod环境中

Symfony1 如何防止调试工具栏出现在prod环境中,symfony1,Symfony1,我最近部署了一个Symfony 1.3.6网站。我选择将frontend_dev.php保留在服务器上,以便在绝对需要时在本地计算机上进行调试 我修改了frontend_dev.php如下: <?php require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php'); $configuration = ProjectConfiguration::getApplicationConfiguration

我最近部署了一个Symfony 1.3.6网站。我选择将frontend_dev.php保留在服务器上,以便在绝对需要时在本地计算机上进行调试

我修改了frontend_dev.php如下:

<?php

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);

// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
    //in case something screwy happens ...
    try
    {
       // die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
       sfContext::createInstance($configuration)->getController()->forward('security', 'error404');
       exit();
    }
    catch(Exception $e)
    {
        //if we got here, all bets are off anyway, just go away ....
        exit();
    }
}

sfContext::createInstance($configuration)->dispatch();

您正在启用调试的开发环境中初始化配置。尝试以下方法:

// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
    //in case something screwy happens ...
    try
    {
       // die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
       $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);

       sfContext::createInstance($configuration)->getController()->forward('security', 'error404');
       exit();
    }
    catch(Exception $e)
    {
        //if we got here, all bets are off anyway, just go away ....
        exit();
    }
}
else
{
  $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
  sfContext::createInstance($configuration)->dispatch();
}

sfConfig::set('sf\u web\u debug',false)

您不想在
设置.yml
文件中关闭它吗

dev:
  .settings:
    web_debug: false

这将关闭调试工具栏。不过,您仍将在可能具有不同配置的开发环境中运行应用程序。Coronatus:这将打开调试工具栏的第一个(error404)页面,但该页面上的链接(例如返回主页),仍然显示调试工具栏,因此将该行放在全局文件中。这有助于我在Ajax响应中关闭工具栏。我个人刚刚在代码中向数组添加了我的IP地址,以允许临时访问前端开发控制器,然后将其删除。