我正在尝试完成每次用户访问某个页面时将值添加到会话变量(数组)的功能。这是我来自控制器的代码:
public function actionPut($id)
{
$session=new CHttpSession;
$session->open();
if (empty($session['the_variable'])) {
$session['the_variable'] = array($id);
}
else {
$session['the_variable'][] = $id;
}
$session->close();
$this->render('test', array('session'=>$session));
}
但它不起作用。如果变量为空,则只存储第一次的信息。下次我访问该页面时,它不会为数组添加值。我也尝试过push_array
功能,但没有运气。怎么了?