change Yii:app()->params value?

in params.php

Yii::app()->params[‘siteId’] = ‘99999’;

After the user login in UserIdentity I did this :

Yii::app()->params[‘siteId’] = $this->user->SiteId;

It still refers to ‘99999’, am I doing it wrongly?


Are you talking about 2 different requests? Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.

Maybe better use the session to store user specific values.

It’s going to reload those params each time a request is received. It’s a configuration array rather than a persistent storage mechanism.

Try using the user’s stash instead – on login:

 Yii::app()->user->setStash('siteId', $this->user->SiteId );

And, to make it more friendly to your site code, you can extend the CWebUser to add set/getSiteId() methods, which will enable you to reference it quickly just by using Yii::app()->user->siteId;

Something like:

class WebUser extends CWebUser(

   /* ... existing custom methods here ... */


    * Set the site ID for this user

    * @param int $x Site ID


   public function setSiteId( $x )


      $this->setStash('siteId', $x );



    * Get the site ID for the current user

    * @return int


   public function getSiteId( )


      // Add any default logic here ..

      $id = $this->getStash('siteId');

      if ( !$id )


         return Yii::app()->params['siteId']; // return the default




Then in your login method, you simply:

 Yii::app()->user->siteId = $this->user->siteId; 

Dana i think you meant State instead of Stash :)

Hah, too much git stashing for me today!

For 2 months I stopped coding this part and Googled for the solution. This, my own thread turn up 1st in the result! Thanks Mike and Dana!

You’re very welcome =)