Yii->app()->user->id is null when logged in

Hello all,

My problem is as follows: In general, Yii::app()->user and its various attributes work just fine for me. However, I am making an Ajax call to a controller while logged in, attempting to build a new User object with a user’s id. But Yii::app()->user is outputted as Guest, and Yii::app()->user->id is coming out as null. Therefore my user object is useless.

I’m not at all sure what kind of information you guys might need for debugging. Can someone set me on the right track or some clarifying questions?



What version of Yii are you using? I remember I had similar problems with older versions. Solution was something like that:




 	'useTransparentSessionID'   =>($_POST['PHPSESSID']) ? true : false,

 	'cookieMode'            	=>($_POST['PHPSESSID']) ? 'none' : 'allow',



That’s of course in main config file.

Thanks for responding. I’m on Yii v1.1.8.

I’ll have to try this solution out later today when I’m not at work. Is there somewhere I can read about Yii sessions to derive the code you suggested below? I hate using code blind, although I will try it out tonight regardless.


Yii uses native php sessions:


PHP: Sessions

Somehow, the problem fixed itself. I booted up the site and had no more problems. I will definitely look into CHttpSession, although I am not yet sure what advantages it provides.


Daniel Moniz