2017-02-20 19 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