What is the best way to get the 'Request' object in the controller?

前端 未结 2 1695
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 22:55

I have seen the request object being passed to the controller action method as a parameter like this:

public function addAddressAction(Request $request)
{
           


        
2条回答
  •  北海茫月
    2021-01-03 23:17

    As far as I know there's no difference. It doesn't interrupt affect much either way. Even if you want to specify required parameters in your action. E.g.

    /**
     * @Route("/edit/{id}", name="edit")
     */
    public function editAction(Request $request, $id)
    {
        // Both $request and $id are available
    }
    

提交回复
热议问题