Symfony doc says:
During each request, Symfony2 will set the global application of the template variable in both the Twig template models and in PHP by default. The app variable is an instance of GlobalVariables that will give you access to some automatic application variables:
app.security - security context.
app.user is the current user object.
app.request is the request object.
app.session - session object.
app.environment - the current environment (dev, prod, etc.).
app.debug - True if in debug mode. False otherwise.
Examples:
In the branch: {{ app.request.method }}
In PHP: echo $app->getRequest()->getMethod() In a branch: {{ app.user.username }}
But for the session object:
In the branch: {{ app.session.varname }}
In PHP: // I don't know, do you know how to call it?
I tried: $session = $app->getSession('uid'); but when I try to store it in the database, it tells me:
Catchable Fatal Error: an object of class Symfony \ Component \ HttpFoundation \ Session cannot be converted to a string in C: \ wamp \ www ...
There is a lack of resources when it comes to PHP templates, but in my case I cannot switch for some reason.
Question in other words, which is equivalent to a PHP template:
{{ app.session.varname }} ?
php templates symfony session
Nadjib mami
source share