How To Extend User Class In Yii2 And Add It To Project

There is CWebUser class in Yii1.1.13. This class was a core class in Yii1.1.13 and there is no way to extend this class and to add in it some functionalities.

Now in Yii2 I see there is no core class which works with user authorization. So I think it is possible to extend User class in Yii2 and to add in it some my own usefull functions and properties. So what is the way to do that? Is it easy? Can I not use any authorization and User class in my site at all? It is good for development if it is correct.

Thanks.

CWebUser is renamed to yii\web\User in Yii 2. In both 1.1 and 2.0 you can extend this class and change the "user" application component to use your own version.

Do you mean this way?


return array(

    'components'=>array(

        'user'=>array(

            'class'=>'ext.path.to.userclass'

        ),


    ),

);

And what about ‘log’, ‘errorHandler’, ‘formatter’, ‘i18n’, ‘urlManager’, ‘view’ components? They are in core in Yii2. Can I expand its classes and use them as components in config file? It may be needed sometimes and it will be very good.

I have made tests and it works exactly what I said. I can extends core components. It is good.