【发布时间】:2012-03-09 13:02:41
【问题描述】:
编辑: 简而言之:有没有办法调用 $kernel->getRootDir();从树枝扩展中?或者可能来自 DI 容器?
原始问题:
我尝试使用 Imagine 来缩放服务器上的图像。一切正常,因为我不尝试通过命令行触发渲染: 在这种情况下,看起来路径设置错误 - 我收到错误:
[Twig_Error_Runtime]
在渲染模板期间引发了异常 (“文件 ../web/documents/4f59ef3f76e74_test3.jpg 不存在”) “....:detail.html.twig”在第 72 行。
我使用的是我自己写的 twig 标签:
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);
$path 设置为“documents/4f59ef3f76e74_test3.jpg” “documents/”是“web”的子目录
有什么想法吗?
【问题讨论】: