我有一个类扩展\Twig_Extension
如下:
class MYTwigExtension extends \Twig_Extension
{
protected $doctrine;
protected $router;
public function __construct(RegistryInterface $doctrine , $router)
{
$this->doctrine = $doctrine;
$this->router = $router;
}
public function auth_links($user , $request)
{
// Some other codes here ...
// HOW TO GENERATE $iconlink which is like '/path/to/an/image'
$html .= "<img src=\"$iconlink\" alt=\"\" /> ";
echo $html;
}
}
我的问题是如何在 Twig 扩展中生成资产链接?我想替换我班上的资产助手。基本上我不知道我必须在这里注入或使用什么!提前致谢。
<img src="{{ asset('img/icons/modules/timesheet.png') }}" alt="" />