Yii Framework Forum: How To Extend User Class In Yii2 And Add It To Project - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   egorpromo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 02-December 12

Posted 11 July 2013 - 07:44 AM

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.
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,889
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 July 2013 - 11:05 AM

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.
0

#3 User is offline   egorpromo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 02-December 12

Posted 12 July 2013 - 07:21 AM

View Postqiang, on 11 July 2013 - 11:05 AM, said:

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.
0

#4 User is offline   egorpromo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 02-December 12

Posted 13 July 2013 - 07:01 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users