内核中的Symfony getparameter
调用内核时,我尝试获取getParameter:内核中的Symfony getparameter,symfony,Symfony,调用内核时,我尝试获取getParameter: //$this->_kernel = new \AppKernel("dev", true); $this->_kernel = new \AppKernel($this->_container->getParameter('env'), true); $this->_kernel->boot(); $this->_container = $this->_kernel->
//$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”
对不起,我的英语不好。我认为你不需要这样的环境。如果您查看
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
谢谢,但是要使用这个函数,我需要在调用内核之前调用它。所以当我创建内核时,我不能调用getEnvironment,比如:$this->\u kernel=new\AppKernel($this->\u kernel->getEnvironment(),true);不,请查看您的app.php
文件。您可以在这里为内核定义env。在此之前,您没有内核来加载配置变量。那没有意义。。。这是应用程序的第一个入口点。你为什么需要这样一个结构?