We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Session Issue

How to use session on a view page phalcon I want to save specific value in new session variable



1.7k
edited Sep '14

you can access session directly in your view
Just print it out

{{ session.something }}

or something like this

{% if session.userid is 1 %}
    {{ 'is 1' }}
{% else %}
    {{ 'Not 1' }}
{% endif %}


27.6k

i want to save into session not using volt



7.9k
Accepted
answer
edited Sep '14

If you are using volt you are able to use service that you have define in depency container

here is some refence : https://docs.phalcon.io/en/latest/reference/volt.html#inject-services-into-a-template

If you wan set session within view

{{ session.set("key", "value") }}

if you dont want use vold you could access DI in static way fro your view

$session = Phalcon\DI::getDefault()->getSession(); $session->set("key", "value");



1.7k

Why do you need to set session value in your view?
It's probably not a good idea

I think you can just do it in your controller.



27.6k

how to destroy session in a view itself



765
edited Sep '14

https://docs.phalcon.io/en/latest/api/Phalcon_Session_Adapter.html

{{ session.destroy() }} or $session->destroy();