我正在使用 Symfony 2,我想从服务类而不是模板生成 Assets 的绝对 URL。我想要同样的东西
{{ asset('/path/to/my/asset') }}
将在模板中返回。
这可能吗?
最佳答案
看看: Symfony/Bundle/TwigBundle/扩展/ Assets 扩展
public function getAssetUrl($path, $packageName = null)
{
return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
}
基本上,将 templating.helper.assets 注入(inject)您的服务,然后调用 getUrl。
关于php - 如何从服务中生成 Assets URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9180141/