session return nothing when move to another page

I have a page that used to store a session and then I want to retrieve the value of those session in another page. But when I try to retrieve it, it return nothing.

The script something like this:

Page A(add session value)

Yii::app()->session[‘parent’] = ‘Example’;

And then I move to Page B by click a link in Page A,

Page B(retrieve the initiated session above)

echo Yii::app()->session[‘parent’];

In page B, script above return nothing. AFAIK, in PHP session it would available in whole system. Does Yii has a configuration to manage session it self so it would available in whole system? or something wrong based on my script?

you can try:

Yii::app()->user->setStatus(‘key’, $value);

Thanks for your response liu,

is that works same as setState(‘key’, $value) ? setState stored in client as cookie, I need something stored as session.

Yii::app()->session should work as you expect, without any configuration. For debugging I recommend the following:

  • If your site has subdomains check if PageB is under the same subdomain as PageA. Session cookie may not be sent back by the browser if subdomain is different.

  • If you have any configuration for session component try to comment it out, and check if it works.

  • Try to use session_start() and $_SESSION array directly to make sure that nothing is wrong with your php (or browser) configuration.

Well, I found what the problem is…when I try to add static value to session


Yii::app()->session['test'] = 'test';

it works, I can retrieve the value.

What I want is session variable receive a dynamic value from model,


Yii::app()->session['test'] = $model->title;

The $model->title above add nothing to session. When I try to debug using Yii::app()->user->setFlash it’s fine, it’s return $model->title value.

when I try to pass $model->title to a variable then add it to session, it’s not working as well…