使用session或cookie cakephp 2.4保持第一次访问第二次访问的参数

时间:2014-02-05 04:57:21

标签: cakephp cakephp-2.4

class GroupsController extends AppController {
    public function beforeFilter() {
        parent::beforeFilter();
        debug($this->Session->read('selected'));  // ="c"  I expect
        debug($this->request->query('selected'));
        if ($this->request->query('selected') != null){
            $this->Session->write("selected",$this->request->query('selected'));
        }
debug($this->Cookie->read("test")); //== array('SID' => 'm3fmjpdp9c2',**I want this 'test' => 'test'**)
        if ($this->Cookie->read("test") == null){
            $this->Cookie->write("test","test");
            debug("newed");
        }
    debug($this->Cookie->read("test")); // == array(    'SID' => 'mjpdp9c2',    'test' => 'test'  )

    }
/**
 * Components
 *
 * @var array
 */
    public $components = array('Paginator');

/**
 * index method
 *
 * @return void
 */
    public function index() {
        $this->Group->recursive = 0;
        $this->set('groups', $this->Paginator->paginate());
        debug($this->Session->read('selected'));
    }

此网址为cakephp / groups

第1个cakephp / groups?选择= c 调试($这 - >会话而>读取( '选择')); // =“c” 它返回

第二个cakephp / groups

我想要 调试($这 - >会话而>读取( '选择')); // =“c”我希望

第二次。但现在为空。

0 个答案:

没有答案