我试图为缓存和日志目录包含自定义值。原因是让它与Vagrant一起快速工作。
这是具有静态值的缓存方法(在app/AppKernel.php
内):
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/dev/shm/project/app/cache/' . $this->environment;
}
return parent::getCacheDir();
}
我想做类似的事情:
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return $this->getContainer()->getParameter('cache_dir') . $this->environment;
}
return parent::getCacheDir();
}
然后,在parameters.yml
:
cache_dir: '/dev/shm/project/app/cache/'
但是$this->getContainer()
在这里返回null。我试图将容器放入其他内核方法中但没有成功。有没有想过它是否可能?
答案 0 :(得分:0)
您总是可以尝试定义允许您将缓存目录作为服务获取的类,然后将服务容器传递到该类中。
services:
your_cache_dir_service:
class: Acme\TestBundle\Services\CacheHelper
arguments: [@service_container]