php-mvc icon indicating copy to clipboard operation
php-mvc copied to clipboard

Session value access

Open mahmudul-elahi7676 opened this issue 2 years ago • 6 comments

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?

mahmudul-elahi7676 avatar Nov 14 '23 07:11 mahmudul-elahi7676

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

daveh avatar Nov 14 '23 10:11 daveh

But how to pass session variables in base.html file?

mahmudul-elahi7676 avatar Nov 14 '23 20:11 mahmudul-elahi7676

You can set it as a global variable, e.g.

$twig->addGlobal('session', $_SESSION);

daveh avatar Nov 15 '23 10:11 daveh

You can set it as a global variable, e.g.

$twig->addGlobal('session', $_SESSION);

Thank you sir it works. :)

mahmudul-elahi7676 avatar Nov 17 '23 15:11 mahmudul-elahi7676