Anybody have an idea, why cookie in Cakephp always get deleted automatically after function ends?
I try to write a cookie in let say function abc, with following :
$this->Cookie->write('referal', $ref);
Before that, in app controller before filter, i have initialized the cookie as following :
$this->Cookie->name = 'renttycoons';
$this->Cookie->time = 604800; // or '1 week'
$this->Cookie->path = '/';
$this-&开发者_C百科gt;Cookie->domain = 'rent.local';
$this->Cookie->key = 'qSI232qs*&sXOw!';
But once the execution of function ends, the cookie was empty. when i try to read the cookie before function abc ends, it was there. There was no delete cookie method anyway.
yes, because the way Cookie in Cake works: when you use Cookie->write(), it doesn't directly write to the cookie, because the cookie is in the user's browser. Only until the view is rendered that the cookie you wrote is sent. So when you redirect, (I would guess the cookie doesn't get sent and flushed out because the view isn't rendered) the new request has the old cookie data.
If you want to persist some shared data within cake app, and unique to each visitor, use SessionComponent. It looks pretty much the same as Cookie: $this->Session->write('referal', $ref);
and $this->Session->read('referal');
精彩评论