在symfony中以交互方式启用调试模式
我使用symfony 1.4与Doctrine。在symfony中以交互方式启用调试模式
我试图找到一种方法来启用调试模式只有当前sfUser
有一个特殊的debugger
凭据。
我已经创建了一个过滤器,停用symfony的调试工具栏,如果sfUser
还没有这个证书(该web_debug
设置为true
在我settings.yml
文件):
class checkWebDebugFilter extends sfFilter
{
public function execute($filterChain)
{
if(!$this->getContext()->getUser()->hasCredential('debugger'))
{
sfConfig::set('sf_web_debug', false);
}
$filterChain->execute();
}
}
我index.php
文件的代码是:
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false));
sfContext::createInstance($configuration)->dispatch();
的问题是,随着debug
模式在我index.php
硬编码为false
,它是一个也对调试器禁用;因此Web调试栏不显示Doctrine语句或时序指示。
只有当前sfUser
有一个精确的凭证时,才有办法启用调试模式吗?
我尝试添加sfConfig::set('sf_debug', true);
我checkWebDebugFilter::execute()
方法,但作为过滤器后主义语句执行,他们不会被记录。
我也试图在我的index.php
文件中添加session_start();
,然后通过$_SESSION
变量浏览检查当前用户是否具有debugger
证书,但它没有工作(和它在symfony中的精神是不是要么)。
在此先感谢您的答案。
试试这个
如果要启用web_debug面板(开发)模式,然后在你的index.php '前端', '开发'
http://host_url/frontend_dev.php
或
写,真正。
require_once(dirname(FILE)。'/ ../config/ProjectConfiguration.class.php'); $ configuration = ProjectConfiguration :: getApplicationConfiguration('frontend','dev',true)); sfContext :: createInstance($ configuration) - > dispatch();
感谢您的答复,但恐怕您不明白这个问题;问题不是激活调试模式,而是激活它_interactively_。这意味着我正在找到一种方法来改变当前'sfUser'(及其凭证之一)上'index.php'_depending_的内容。 – Phen 2011-03-15 11:39:50
当您在index.php文件中传递调试参数时,它实际上传递给应用程序的sfApplicationConfiguration类。在你的情况下,它可以在/apps/frontend/config/frontendConfiguration.class.php文件中找到。 frontendConfiguration类扩展了sfApplicationConfiguration,在这里你可以添加你的代码。
调试参数存储在这个类的一个受保护的变量,那么您将无法将其从过滤器的变化,但您可以创建例如功能:
setDebug($mode) {
$this->debug = $mode;
}
,并调用它在你的过滤器:
$this->context->getConfiguration()->setDebug(true);
你也可以覆盖frontendConfiguration类isDebug()函数,因为那是在initConfiguration()函数用来初始化时序指标和其它调试的东西。
if ($this->isDebug() && !sfWebDebugPanelTimer::isStarted())
{
sfWebDebugPanelTimer::startTime();
}
但是你不能在这里检查用户权限,因为在这个阶段sfUser类不会被初始化。但是,您可以检查$ _COOKIES或$ _SESSION全局变量,以获取用户登录时可以设置的值。或者,您可以在Filter中调用sfWebDebugPanelTimer :: startTime(),但会丢失几微秒。
我还没有测试过,但这就是我要做的。
我认为最好的方法是在用户拥有证书时设置另一个上下文。我正在使用一种解决方案,但尚未使其工作 – Pabloks 2011-03-12 21:20:46