Extend CWebUser


I’m new to Yii Framework. I’m working with 1.0.10 branch.

I’m trying to extend functionality to CWebUser, especyficaly, I’m trying to add a isAdmin and a isRegistered methods. I placed a new class WebUser in /protected/components, which is extending the original CWebUser. Inside, I placed a couple of new public methods, like this:



 * Overload of CWebUser to set some more methods.


class WebUser extends CWebUser


        public function isAdmin()


                // When Users are implemented, change this to check roles.

                return ( $this->getName() == 'admin' );


        public function isRegistered()


                return ( !$this->isGuest() && !$this->isAdmin() );



Then I added a line in config/main.php to tell Yii to use this new class:

        // application components



                        // use a customized class, placed in 'components'


Then, I tried to use these new methods in the layout/main.php:

<?php $this->widget('application.components.MainMenu',array(


                array('label'=>'Backoffice', 'url'=>array('/site/backoffice_main'), 'visible'=>Yii::app()->user->isAdmin),


And finally, went to the browser and…


I’ve tried to take off the class param in the config/main.php > components and then the exception says Property “CWebUser.isAdmin” is not defined, so may I understand the new class is being declared?

Did I left any step?

thank you.

Ok, I figured out by myself:

The line:


goes for attributes of the class. So, I had to change it to:


Note the parenthesis.

Nothing like being a novice ;)

thank you.

You should use getIsAdmin() in your extended Webuser class as function name, then you can do the following:


I am having similar issue. All I want is to save user’s lastLoginTime to be saved into DB

All I have for WebUser is:


// this file must be stored in:

// protected/components/WebUser.php

class WebUser extends CWebUser {

public function afterLogout()








For now logOutDateTime in my database is just varChar so I assume every time a user logs out it should write ‘TEST’ in to that filed but it does nothing.

in my Config/main.php I have this line







Where did I go wrong?