php-mvc
php-mvc copied to clipboard
Session value access
I have set session value like login= true , role = admin How to access this data in base.html
I already try {{ app.session.get(‘user_id’) }} But im not getting any value Can you please help me?
What is in the app variable? This isn't a variable that the framework provides - to access the session you need to pass the session to the template, or use plain PHP inside the template, e.g. $_SESSION
But how to pass session variables in base.html file?
You can set it as a global variable, e.g.
$twig->addGlobal('session', $_SESSION);
You can set it as a global variable, e.g.
$twig->addGlobal('session', $_SESSION);
Thank you sir it works. :)