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 to use cookies in models?

How to use cookies from models ? Cookies from controller work is normally but from models does not work, why?



85.5k
Accepted
answer

$t = \Phalcon\Di::getDefault()->get("cookies");

$t->set("name etc ... ')...

After reading 3.0 notes and saying that $di is now in $this I wonder if it will be possible to use $this->session in models instead of $this->getDI()->getSession(). Need to upgrade and test next week, no time now :(

edited Aug '16

I'm guessing that you really didn't read 3.0 notes. It's saying that your service definition is bound to di(so functions are the methods in Phalcon\Di object, this is why you can use $this. Are your models are defined in di as service defnition ?