No session Cookie

Hi all

im making an action that will only return json string but what i need is when i call this action

is to send back the session cookie,the problem is the application not creating the session cookie when a call it

my action looks like


                echo "{\"errorCode\":$errorCode}";


                Yii::app()->end();

When i call other actions (e.g the home page )the cookie created successfully,

Thanks in advance,

P.S

After i put this statement before the above code the cookie created successfully


        Yii::app()->session;

echo "{\"errorCode\":$errorCode}";


                Yii::app()->end();

I don’t know why :)

Can any one please explain it to me

it is becuse Yii does not create any component unless it is needed… when you call Yii::app()->session then session object is instantiated for the first time and cookie is set. Same with every component - database connection is not created unless you access Yii::app()->db, and so on.

Thanks redguy

But why the cookie not created(without using Yii::app()->session) on this action like other actions?

maybe other actions have accessRules which check if user is logged, which initializes session in background… hard to tell without investigating your code.

You are right i have only a controller with this action only ,no rules or other stuff.