我正在使用CakePHP 2.2.3版。我想以像 -
这样的数组格式获取我的cookieArray
(
[0] => Array
(
[username] => test1
)
[1] => Array
(
[username] => test2
)
[2] => Array
(
[username] => test3
)
)
下面的代码我收到错误消息。请检查我的代码。
public function broadcast($username=null) { //test1 or test2 or test3
$this->layout = '';
$recent = $this->Cookie->read('recentUser');
$amount = count($recent);
$cookieVal = array('username'=>$username);
$this->Cookie->write('recentUser.' . $amount, $cookieVal);
$test = $this->Cookie->read('recentUser');
pr($test);
exit;
}
输出:
Warning (512): You cannot use an empty key for Security::cipher() [CORE\Cake\Utility\Security.php, line 186]
Array
(
[0] => Array
(
[username] => test3
)
)
总是我收到上次访问的最后一个cookie时出现Secrity::chiper()
错误。请问如何以上述格式显示多个cookie?
答案 0 :(得分:0)
你能试一试,看看这是否能解决你的问题
public function broadcast($username=null) { //test1 or test2 or test3
$this->layout = '';
$recent = $this->Cookie->read('recentUser');
$amount = count($recent);
$amount++; //Custom
$cookieVal = array('username'=>$username);
$this->Cookie->write('recentUser.' . $amount, $cookieVal);
$test = $this->Cookie->read('recentUser');
pr($test);
exit;
}