[英]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.