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

How cookies SET in volt?

Hey guys!

I need set cookie in phalcon (don't ask "why" please). but i have a error: Invalid token SET.

{{cookies.set('refer', 123)}}

but GET cookie is OK. (not "refer", other).

How i can set cookie in volt?



145.0k
Accepted
answer

I will still ask why. You should do it in controller action. Beacause cookies are send only if response is send. If you use view you don't have to return always response with it.

Just use RAW PHP; But I have to say it is bad code to have changes in the view.

<?php setcookie("refer", 123); ?>

I guess this is beacause set keyword is used in volt already. Like {% set variable = "asd"%} but it's just a guess.

thanks guys. forgot that you can do this in the controller, and made life difficult for yourself.