Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Session Issue

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

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 %}


16.7k

i want to save into session not using volt



5.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 : http://docs.phalconphp.com/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");

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.



16.7k

how to destroy session in a view itself



568
edited Sep '14

http://docs.phalconphp.com/en/latest/api/Phalcon%5Session%5Adapter.html

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