Symfony - generate url with parameter in controller

后端 未结 4 1963
花落未央
花落未央 2021-02-01 01:00

I want to generate a Url directly in my controller. I want to user a url defined in my routing.yml file that needs a parameter.

I\'ve found that code in the Cookbook (Ro

4条回答
  •  既然无缘
    2021-02-01 01:21

    make sure your controller extends Symfony\Bundle\FrameworkBundle\Controller\Controller;

    you should also check app/console debug:router in terminal to see what name symfony has named the route

    in my case it used a minus instead of an underscore

    i.e blog-show

    $uri = $this->generateUrl('blog-show', ['slug' => 'my-blog-post']);
    

提交回复
热议问题