Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session value access #126

Open
mahmudul-elahi7676 opened this issue Nov 14, 2023 · 4 comments
Open

Session value access #126

mahmudul-elahi7676 opened this issue Nov 14, 2023 · 4 comments

Comments

@mahmudul-elahi7676
Copy link

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?

@daveh
Copy link
Owner

daveh commented Nov 14, 2023

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

@mahmudul-elahi7676
Copy link
Author

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

@daveh
Copy link
Owner

daveh commented Nov 15, 2023

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

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

@mahmudul-elahi7676
Copy link
Author

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

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

Thank you sir it works. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants