Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:12:04+00:00 2026-06-15T08:12:04+00:00

Disclaimer: Complete beginner in Yii, Some experience in php. In Yii, Is it OK

  • 0

Disclaimer: Complete beginner in Yii, Some experience in php.
In Yii, Is it OK to override the login method of CWebUser?
The reason i want to do this is because the comments in the source code stated that the changeIdentity method can be overridden by child classes but because i want to send more parameters to this method i was thinking of overriding the login method too (of CWebUser).
Also if that isn’t such a good idea how do you send the extra parameters into the changeIdentity method.(By retrieving it from the $states argument somehow ??). The extra parameters are newly defined properties of UserIdentity class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:12:05+00:00Added an answer on June 15, 2026 at 8:12 am

    It is better to first try to do what you wish to do by overriding components/UserIdentity.php‘s authenticate method. In fact, that is necessary to implement any security system more advanced than the default demo and admin logins it starts you with.

    In that method, you can use

    $this->setState('myVar', 5);

    and then access that anywhere in the web app like so:

    Yii::app()->user->getState('myVar');

    If myVar is not defined, that method will return null by default. Otherwise it will return whatever it was stored as, in my example, 5. These values are stored in the $_SESSION variable, so they persist as long as the session does.

    UPDATE: Okay, took the time to learn how this whole mess works in Yii for another answer, so I’m sharing my findings here as well. The below is mostly copy pasted from a similar answer I just gave elsewhere. This is tested as working and persisting from page to page on my system.

    You need to extend the CWebUser class to achieve the results you want.

    class WebUser extends CWebUser{
        protected $_myVar = 'myvar_default';
    
        public function getMyVar(){
            $myVar = Yii::app()->user->getState('myVar');
            return (null!==$myVar)?$myVar:$this->_myVar;
        }
    
        public function setMyVar($value){
            Yii::app()->user->setState('myVar', $value);
        }
    }
    

    You can then assign and recall the myVar attribute by using Yii::app()->user->myVar.

    Place the above class in components/WebUser.php, or anywhere that it will be loaded or autoloaded.

    Change your config file to use your new WebUser class and you should be all set.

    'components'=>
        'user'=>array(
            'class'=>'WebUser',
        ),
    ...
    ),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer : I kept this because some things may be useful to others, however,
Disclaimer: This is homework. I am attempting it and do not expect or want
DISCLAIMER - I am total PHP noob - looking for some help/tips on how
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
Disclaimer: this question is driven by my personal curiosity more than an actual need
Full disclaimer: this is not really a homework, but I tagged it as such
Disclaimer : this is a strange issue that only happens in a Kindle Fire
Disclaimer: this question is purely informational and does not represent an actual problem I'm
Disclaimer: I'm new to most of this I just downloaded virtualbox yesterday and installed
Disclaimer: I am new to python and django but have Drupal programming experience. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.