[英]In symfony 2 how to access twig templating base url parameter in php?
如何在服務或任何其他類中訪問基本URL?
framework:
templating:
engines: ['twig']
packages:
assets:
base_urls: ["http://assets.acme.com"]
通常:
$assetUrl = $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
在您的情況下:
$baseUrl = $this->container->get('templating.helper.assets')->getUrl('', 'assets');
我想你的代碼在app/config/config/yml
看,這段代碼在我的控制器中:
use Symfony\Component\Yaml\Yaml;
[...]
$configfile = Yaml::parse($this->get('kernel')->getRootDir().'/config/config.yml');
baseurls = $configfile['framework']['templating']['packages']['assets']['base_urls']);
您必須在參數部分提及base_url,例如
參數:
base_urls: http : //assets.acme.com
然后借助容器對象,您可以訪問任何服務或類。
像在Controllar中使用
$ this-> container-> getParameter('base_urls');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.