Multiple pattern in single symfony routing

后端 未结 4 1168
萌比男神i
萌比男神i 2020-12-29 04:41

How to make multiple pattern in single Symfony routing?

Normally we have a routing as

blog:
    pattern:   /
    defaults:  { _controller: AcmeBlogB         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 05:09

    Just to add to john's answer:

    I use it a lot with FOSJsRoutingBundle:

    /**
     * @Route("/", name="route_name_1", options={"expose"=true})
     * @Route("/{id}", name="route_name_2", options={"expose"=true})
     * @Method("GET")
     * @Template()
     */
    

    This way I have one method and two routes.

    Just remember to set default $id value:

    public function indexAction($id = null)
    {
       ...
    }
    

提交回复
热议问题