我想在用户登录时写入cookie,并希望下次用户打开该页面时,它读取cookie名称并在登录前显示。 foloowing是我使用的代码: - 视图如何在cakephp中读取cookie 2
var $components = array('Cookie');
function beforeFilter()
{
$this->Cookie->name = 'LOGIN_COOKIE';
$this->Cookie->time = time()+60*60*24*30; //cookie expire after 30 days
$this->Cookie->path = '/';
$this->Cookie->domain = 'example.com/';
$this->Cookie->secure = false;
$this->Cookie->key = '39lbkutg1i2l0kta6785d8qki5';
$this->Cookie->httpOnly = true;
}
在登录功能
$this->Cookie->write('COOKIE_USER', array(
'name' => $UserDetails['SystemUser']['Name'],
'email' => $UserDetails['SystemUser']['email'],
'lastname' => $UserDetails['SystemUser']['LastName']
));
我
$readCookie=$this->Cookie->read('COOKIE_USER');
,但它给错误 “缺少帮手”
Error: CookieHelper could not be found.
Error: Create the class CookieHelper below in file: app/View/Helper/CookieHelper.php
请指导我。
这个代码?您使用Cookie组件,但尝试使用Cookie助手阅读而不加载它...... –
如果用户之前访问过我们的网站,我需要在视图中显示名称和电子邮件。 所以我必须阅读cookie。你知道我该如何显示名称和电子邮件? –
是的,我知道,看下面的答案... –