Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use instead of getRequest()->get(...) in controller

Tags:

symfony

Recently I browsed symfony2 api docs and here is what i've found in documentation for Request's get method:

Avoid using this method in controllers:

  • slow
  • prefer to get from a "named" source

So what is the "named" source that I should use instead of get method?

like image 753
Molecular Man Avatar asked Nov 05 '12 20:11

Molecular Man


1 Answers

"named" source would be appropriate parameter bag:

  • $request->query for GET parameters
  • $request->attributes for request attributes (parsed from PATH_INFO)
  • $request->request for POST parameters

get method simply goes through all of them until it finds a parameter by name. Therefore its slow. See the implementation.

like image 164
Jakub Zalas Avatar answered Oct 11 '22 14:10

Jakub Zalas