Can anybody knows how can I get the parameters.yml (or _dev) in the AppKernel.php ?
I want to change the getLogDir() variables('mylogsdir') dynamicly ?
AppKernel.php :
$this->rootDir.'/'.$this->environment.'/'.$myLogDir;
parameters.yml:
parameters:
myLogDir: 'logdir'
Is it possible ?
Thanks a lot Fabrice
You can try something like this:
In 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;
}
I've the solution, here in the vhost under nginx :
fastcgi_param SYMFONY__KERNEL__LOGS_DIR "/path/to/logs";
fastcgi_param SYMFONY__KERNEL__CACHE_DIR "/path/to/cache";
And, in the AppKernel.php file :
public function getCacheDir()
{
if (!empty($this->getEnvParameters()['kernel.cache_dir'])) {
return $this->getEnvParameters()['kernel.cache_dir'].'/'.$this->environment;
} else {
return parent::getCacheDir();
}
}
public function getLogDir()
{
if (!empty($this->getEnvParameters()['kernel.logs_dir'])) {
return $this->getEnvParameters()['kernel.logs_dir'].'/'.$this->environment;
} else {
return parent::getLogDir();
}
}
thanks,
Fabrice
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With