Which access to route parameters is faster?
$this->getRequest()->get('param')
And what about request object? Better way is put request object as controller parameter or call getRequest()
method on controller object?
One could argue that since you need to pull Request
object from container it's slower approach, but I've done both and difference is negligible. When you need Request
object it's better to put it as the controller method argument, because you'll have it immediately and PHP Type Hinting will provide additional info (autocomplete and so on) in decent IDEs (I personally recommend PHPStorm). This applies also to other controller method arguments, you are given straight variables, no need to pull them twice from other places.
class SthController extends Controller
{
public function indexAction(Request $request, $arg1, $arg2)
{
// you have $request object with type hint and all goodness
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With