2017-02-20 64 views
-1

我试图让我的getParameter当我打电话给我的内核:的Symfony的getParameter内核

//$this->_kernel = new \AppKernel("dev", true); 
    $this->_kernel = new \AppKernel($this->_container->getParameter('env'), true); 
    $this->_kernel->boot(); 
    $this->_container = $this->_kernel->getContainer(); 
    $this->_logger = $this->_container->get('logger.common'); 

但是,返回NULL,因为我使用的getParameter之前创建我的容器。 当我打电话给这个新的appkernel时,我该如何获得我的'env'?

对不起,我的英语不好。

回答

0

我不认为你需要你的环境。如果您查看您的AppKernel.php,则只有在开发中才会激活捆绑包。

if (in_array($this->getEnvironment(), ['dev', 'test'])) { 
    $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 
    $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 
} 

所以有一个功能$this->getEnvironment

+0

谢谢,但为了使用此功能,我需要先调用我的内核。所以我不能在创建我的内核时调用getenvironement,像这样:$ this - > _ kernel = new \ AppKernel($ this - > _ kernel-> getEnvironment(),true); – Ygg69

+0

不看看你的'app.php'文件。在那里你定义了内核的env。在此之前,您没有内核来加载配置变量。这没有意义......这是您的应用程序的第一个入口点。你为什么需要这样的结构? – Stony