How do I get the $ _REQUEST variable?

I would like to pass a variable to my controller and I need to get its value regardless of its request method (POST or GET), which is equivalent to $ _REQUEST ['myvar'], how to do this?


source to share

2 answers

To get the url attribute that is part of the route, you need to do something like this (in the controller):



If you need to get POST or GET parameter, you should use this code:



If you need to get the value of the $ _SERVER array, you should do this:

$request->server->get(<server_key_name>); //$request->server->get('HTTP_REFERER');




I found the answer ... Instead of using one of the following:

public function indexAction(Request $request)
    $request->query->get('myvar'); //gets GET var.
    $request->request->get('myvar'); //gets POST var.


I need to call get in class Request

public function indexAction(Request $request)

    $myvar = $request->get('myvar', null);




All Articles