Molecular Man
Molecular Man

Reputation: 22386

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

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?

Upvotes: 8

Views: 1646

Answers (1)

Jakub Zalas
Jakub Zalas

Reputation: 36211

"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.

Upvotes: 11

Related Questions