在AppKernel.php中获取parameters.yml参数 [英] Get the parameters.yml params in the AppKernel.php
本文介绍了在AppKernel.php中获取parameters.yml参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在AppKernel.php中获取parameters.yml(或_dev)吗?
Can anybody knows how can I get the parameters.yml (or _dev) in the AppKernel.php ?
我想动态更改getLogDir()变量('mylogsdir')吗?
I want to change the getLogDir() variables('mylogsdir') dynamicly ?
AppKernel.php:
AppKernel.php :
$this->rootDir.'/'.$this->environment.'/'.$myLogDir;
parameters.yml:
parameters.yml:
parameters:
myLogDir: 'logdir'
有可能吗?
非常感谢 面料
推荐答案
您可以尝试执行以下操作:
You can try something like this:
在AppKernel.php中:
...
use Symfony\Component\Yaml\Yaml;
...
class AppKernel extends Kernel
{
....
public function getLogDir()
{
$array = Yaml::parse(file_get_contents($this->getRootDir().'/config/parameters.yml'));
// or
// $this->getRootDir().'/config/parameters_'.$this->getEnvironment().'.yml'
$myLogDir = $array['parameters']['myLogDir'];
return $this->rootDir.'/'.$this->environment.'/'.$myLogDir;
}
这篇关于在AppKernel.php中获取parameters.yml参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文