currently i am modifying an existing CakePhp project and i’d like to set a cookie in a specific page of the project (it has a .ctp file) so first i’ve tried to put the setcookie php code in the top of the .ctp template (before doctype tag as i’d do in a normal php website) but it doesn’t work, no cookie is set.
So my question is, how could i add a cookie to the visitor when hits X page (which its template file is called list.ctp (for example)) of the website?
Thanks a lot to everyone!
set Cookie on components variable in controller
var $components = array('Cookie');In any action, you can write cookie with
$this->Cookie->write('anyname', cookieData, $encrypt = false, $expires = null);To read stored cookie, just call this code
$this->Cookie->read('anyname');