How Generating URLs from a template correctly in Symfony2/Twig

前端 未结 1 571
礼貌的吻别
礼貌的吻别 2020-12-18 18:11

I\'m working with Symfony2 and:

I have this in the routing.yml

_welcome:
    resource: \"@AcmeBundle/Controller/\"
    type:     annotation


        
相关标签:
1条回答
  • 2020-12-18 18:40

    You've to add a route name in your controller route annotations as follow,

    /**
     * @Route("/{page}", name="static")
     */
    public function staticAction($page)
    {
        // ... 
    }
    

    You could then call the twig path helper using that name,

    <a href="{{ path('static', {'page': 'home'}) }}">Home</a>
    
    0 讨论(0)
提交回复
热议问题