Yii 2: override user model
How to properly override user model in yii2?
For example, I want to override general \ models \ User.php
I created frontend \ models \ User.php with the following code:
namespace frontend\models;
use common\models\User as BaseUser;
class User extends BaseUser
{
public static function tableName()
{
return '{{%accounts}}';
}
...
In main.php, when I add
'user'=>array(
'class' => 'frontend\models\User',
),
I am getting error Setting unknown property: frontend \ models \ User :: identityClass
source to share
There are two things you can customize: 1)
'user' => [
'identityClass' => 'common\models\User',
],
and 2
'user' => [
'class' => 'frontend\components\User',
],
You switch them. "identityClass" is your model, "class" is the User component for Yii. By setting the identityClass, you are telling Yii that the User component should use the frontend \ models \ User it identityClass property.
This is the user component https://github.com/yiisoft/yii2-framework/blob/master/web/User.php
In previous versions of Yii2, the frontend \ components \ User.php file was actually added (which yii \ web \ User extended). I can understand why this is confusing now.
What is the new error you are getting?
source to share