Reputation: 9269
I have a twig template with :
{% render controller('MyBundle:Default:leftside') %}
So i have an action leftside in my controller :
public function leftsideAction(Request $request)
I'm trying, in this action to retrieve GET parameters with :
$request->get('MY_PARAM')
But it's always empty, i think, because i render this action in my template, i can't retrieve all my request.
How can i do that ?
Upvotes: 3
Views: 600
Reputation: 20193
That's totally expected due the concept of request stacks.
The Request
supplied to "main" action is, well, MASTER_REQUEST
, while those supplied via render controller
tag are SUBREQUEST
.
You can read more about RequestStack
feature here.
Now, in order to have access parameters defined in MASTER_REQUEST
you need to get request_stack
service and then get the master request. After that, it's business as usual:
public function leftsideAction(Request $request){
$stack = $this->get('request_stack');
$master = $stack->getMasterRequest();
$master->get('MY_PARAM'); // This should work
$request->get('MY_PARAM'); // But this should not
}
Here is the definition of RequestStack
class: link
Upvotes: 3