【发布时间】:2014-03-21 14:47:27
【问题描述】:
在我的Symfony2/web/img 目录中是一个文件del.png,我想在控制器中显示它。
我尝试使用 image_path() 或 image_tag() 之类的函数,但 Symfony 告诉我这是未知函数...
可以这样做:
$html = "<img src='".$request->getBasePath()."/img/del.png' alt='Delete user' border=0>";
return $this->render ('myBundle:stats:menu.html.twig', array('html'=>$html));
或者也像Symfony2 Assetic get asset urls from inside controller, not template中所说的那样
但我认为可以以更简单的方式完成。看起来很简单,所以我可能忘记了一些东西:-( 有什么建议吗?
【问题讨论】:
-
@FDL,在树枝模板中。我想在 PHP 文件中使用它。 ( {{ ... }} 在那里不起作用)
-
...也有 PHP 示例(在选项卡中)。
-
@FDL,我明白了,但你从哪里得到 $view 变量?