I’m trying to accomplish function that adds values to a session variable, which is array, every time user visits certain page. Here’s my code from controller:
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));
}
But it doesn’t work. If the variable is empty, it only stores information for the first time. Next time i visit the page it doesn’t add value to an array.
I’ve also tried push_array function, but no luck.
What is wrong?
Try this solution.