从一个控制器跳转到另一个控制器时,cakephp中的Cookie丢失 [英] Cookie loss in cakephp when jump from one to another controller

查看:229
本文介绍了从一个控制器跳转到另一个控制器时,cakephp中的Cookie丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

  public function beforeFilter(){
parent :: beforeFilter
$ this-> Cookie-> name ='cookie_test';
$ this-> Cookie-> time = 3600;
$ this-> Cookie-> path ='';
$ this-> Cookie-> domain ='';
$ this-> Cookie-> secure = false;
$ this-> Cookie-> key ='39lbkutg1i2l0kta6785d8qki5';
$ this-> Cookie-> httpOnly = true;
}

$ this-> Cookie-> write('log_cookie','log_value');

来设置cookie,它在同一个控制器中工作,但是当我在另一个控制器中检查这个cookie



请给我建议一个答案........谢谢

解决方案

您需要在AppController中加载Cookie组件。

  

public function beforeFilter(){
parent :: beforeFilter();
// $ this-> Cookie-> name ='cookie_test';
// $ this-> Cookie-> time = 3600;
// $ this-> Cookie-> path ='';
// $ this-> Cookie-> domain ='';
// $ this-> Cookie-> secure = false;
// $ this-> Cookie-> key ='39lbkutg1i2l0kta6785d8qki5';
// $ this-> Cookie-> httpOnly = true;
}

删除此整个代码应该为您工作。


I am use

public function beforeFilter() { 
   parent::beforeFilter(); 
   $this->Cookie->name='cookie_test'; 
   $this->Cookie->time=3600; 
   $this->Cookie->path=''; 
   $this->Cookie->domain=''; 
   $this->Cookie->secure=false; 
   $this->Cookie->key='39lbkutg1i2l0kta6785d8qki5'; 
   $this->Cookie->httpOnly=true; 
}

$this->Cookie->write('log_cookie','log_value'); 

to set a cookie, it work in same controller but when i am check this cookie in another controller it not found and not echo any value of cookie.

Please suggest me with an answer........ Thank you

解决方案

you need to load the Cookie component in AppController. Have you done it?

comment all the default value:

public function beforeFilter() { 
   parent::beforeFilter(); 
   //$this->Cookie->name='cookie_test'; 
   //$this->Cookie->time=3600; 
   //$this->Cookie->path=''; 
   //$this->Cookie->domain=''; 
   //$this->Cookie->secure=false; 
   //$this->Cookie->key='39lbkutg1i2l0kta6785d8qki5'; 
   //$this->Cookie->httpOnly=true; 
}

remove this whole code should work for you.

这篇关于从一个控制器跳转到另一个控制器时,cakephp中的Cookie丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆