从 Symfony-2.7开始,asset
不推荐使用 's 方法的第三个参数(一个指示是否生成绝对 url 的布尔值)。
从来源:
@trigger_error('Generating absolute URLs with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED);
所以以兼容 Symfony-3.0 的方式生成它的官方方法变成了:
{{ absolute_url(asset('some/asset.css')) }}
但问题是HttpFoundationExtension
提供absolute_url
依赖的“请求堆栈”在非http请求的情况下为空。
所以它返回原始路径而不进行任何转换:
if (!$request = $this->requestStack->getMasterRequest()) {
return $path;
}
所以问题是 - 如何在基于 CLI 的应用程序中生成完整的 url?
重要说明:http : //symfony.com/doc/current/cookbook/console/sending_emails.html当您使用帮助程序时,此建议并不实际。absolute_url