这让我发疯了。在我的AppController中,我有以下内容:
public function beforeFilter() {
$this->Cookie->name = 'MyCookie';
$this->Cookie->time = '1 year';
$this->Cookie->domain = 'http://mydomain.com';
$firstVisit = $this->Cookie->read('foo');
if ( empty($firstVisit) ) {
$this->set('firstVisit', true);
$this->Cookie->write('foo', 'true');
} else {
$this->set('firstVisit', false);
}
}
这似乎应该可以工作,但不会返回任何内容并且cookie完全空白。
什么可能阻止Cake实际保存Cookie?
答案 0 :(得分:4)
在呈现视图之前,不会设置cookie。也许你没有控制器的视图?
答案 1 :(得分:2)
http://
导致它破裂。删除它解决了问题。