When we want to use twig functions like render controller:
<div id="sidebar"> {{ render(controller( 'AppBundle:Article:recentArticles', { 'max': 3 } )) }} </div>
symfony create a sub-request, with it own params for embedded controller. Sometimes we made have to need data from original Request object (GET/POST/FILES). It’s very simple, and we don’t need to assigned it to variable.
In Request obejct there is dedicated method for this: createFromGlobals()
public function recentArticlesAction(Request $request){ $request = $request->createFromGlobals(); }
Simple. But ok, wait…
Maybe we shouldn’t embed other controller in twig?
Yes, that’s right! Usually we should avoid embeding other controllers for performence reasons. But this is very usefull, when we working with ESI.
{{ render_esi(controller('AppBundle:News:latest', { 'maxPerPage': 5 })) }}
If you don’t know this method of caching, You should read it ASAP, and start using:
http://symfony.com/doc/current/book/http_cache.html#edge-side-includes