2013-02-01 50 views

回答

1

在樹枝的最新版本不工作了{{app.request.uri}}

嘗試{{global.request.uri}}代替。

1

您可能在子請求方面存在問題(控制器的$this->forward或視圖中的{{ render(controller('...')) }}),我更願意使用Twig擴展來實現此目的。

<?php 

namespace AppBundle\Twig\Extension; 

// ...  

class MyExtension extends \Twig_Extension 
{ 
    // ... 

    public function getFunctions() 
    { 
     return [ 
      new \Twig_SimpleFunction('current_locale', [$this, 'currentLocale']), 
      new \Twig_SimpleFunction('current_uri', [$this, 'currentUri']), 
     ]; 
    } 

    public function currentLocale() 
    { 
     return $this->get('request_stack')->getMasterRequest()->getLocale(); 
    } 

    public function currentUri() 
    { 
     return $this->get('request_stack')->getMasterRequest()->getUri(); 
    } 

    public function getName() 
    { 
     return 'my'; 
    } 
} 
1

正如上面所說,一些答案不再有效。

什麼工作對我來說作爲2017'09是這個

{{ url('<current>') }} 
+0

你需要渲染。 –

相關問題