Symfony2:如何在Symfony CLI命令中设置根路径
问题描述:
编辑: 切断这个短路:有没有办法调用$ kernel-> getRootDir();从一个树枝延伸?或者也许从DI容器?Symfony2:如何在Symfony CLI命令中设置根路径
原题:
我尝试通过想象来缩放服务器上的图像。 在这种情况下,它看起来像有一种错误的路径SET-我得到一个错误:
[Twig_Error_Runtime]
,因为我不试图触发通过命令行渲染,一切工作正常日志An exception has been thrown during the rendering of a template ("File ../web/documents/4f59ef3f76e74_test3.jpg doesn't exist") in "....:detail.html.twig" at line 72.
我使用,我写了我自己一个树枝标签:
public function thumbnail($path,$width,$maxHeight=0,$alt="",$absolute=false){
/* @var $imagine \Imagine\Gd\Imagine */
$imagine = $this->container->get('imagine');
//$box = new \Imagine\Image\Box($width, $height);
/* @var $image \Imagine\Image\ImageInterface */
$image = $imagine->open("../web/".$path);
...
我也试过这个(这两部作品时,我通过呈现浏览器请求的模板)
$image = $imagine->open($path);
$路径设置为 “文件/ 4f59ef3f76e74_test3.jpg” “文件/” 是 “网络”
任何想法的一个子目录?
答
Ha-找到它了!这将检索Web文件夹的绝对系统文件路径:
$webRoot = $this->container->get('kernel')->getRootDir()."/../web";
我认为您应该能够在服务配置中定义Twig扩展时注入该参数? '%kernel.root_dir% '或类似的。 –
richsage
2012-03-10 16:24:29
我认为它是$ this-> getContainer()而不是$ this-> container – AchrafSoltani 2015-07-27 17:11:33