2013-01-07 44 views
0

我通过Twigcode将数据从CMS呈现给控制器,并且Controller呈现树枝模板。我想拥有目前的路线。我已经尝试过使用:获取当前路径/路径传递_internal路线

// Controller 
$request = $this->container->get('request'); 
$routeName = $request->get('_route'); 

// or Twigtemplate 
{{ app.request.attributes.get('_route') }} 

但结果是“_internal”。我该如何解决这个问题?

回答

0

您忘记了在Twig模板中调用Twig path函数!

{{ path(app.request.attributes.get('_route')) }} 

代替

{{ app.request.attributes.get('_route') }} 

希望它能帮助!

+0

即时通讯异常:渲染模板期间抛出异常(“_internal”路径有一些缺少必需参数(“控制器”,“路径”,“_format”)。“) – raphidue

+0

看到这个评论:http://stackoverflow.com/questions/7096546/how-to-get-current-route-in-symfony-2#comment14132455_7777229。我猜你的模板是以独立模式渲染的。 –

+0

对不起,我不使用独立模式:( – raphidue