Symfony2: Session Global variable in PHP template
php, session, symfony, templates
Solution
In twig: `{{ app.session.varname }}`
In PHP: `echo $app->getSession()->get('uid');`
Problem
Symfony doc says: During each request, Symfony2 will set a global template variable app in both Twig and PHP template engines by default. The app variable is a GlobalVariables instance which will give you access to some application specific variables automatically: app.security - The security context. app.user - The current user object. app.request - The request object. app.session - The session object. app.environment - The current environment (dev, prod, etc). app.debug - True if in debug mode. False otherwise. Examples: In twig: `{{ app.request.method }}` In PHP: `echo $app->getRequest()->getMethod()` In twig: `{{ app.user.username }}` But for the session object: In twig: `{{ app.session.varname }}` In PHP: `// I don't know, do you know how to call it?` I've tried: `$session = $app->getSession('uid');` but when I try to store it to a database it tells me: Catchable Fatal Error: Object of class Symfony\Component\HttpFoundation\Session could not be converted to string in C:\wamp\www... There's a lack of resources when it comes to PHP templates, but in my case I can't switch for some reasons. The question in other words, what is the equivalent in PHP templating of: `{{ app.session.varname }}`?