【发布时间】:2014-10-27 07:23:06
【问题描述】:
我使用的是 CakePHP 2.2.3 版。我想以数组格式获取我的 cookie,例如-
Array
(
[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?
【问题讨论】:
-
要么你没有使用 2.2.3,要么行号错误,
186行将是return $out。你的Security.salt配置值是什么样的? -
@ndm
Secuity.salt问题已解决。 cookiewrite应采用 4 参数name,value, 'false,expire time` 以上代码有效,但我的 cookie 被覆盖。如何在单个变量中设置数组 cookie 值?
标签: cakephp