robregonm / yii2-auth

Yii 2 User Authentication & Role Based Access Control (RBAC) Module
BSD 3-Clause "New" or "Revised" License
77 stars 37 forks source link

Questions on Overriding/Extending the auth\models\User model #17

Closed youanden closed 10 years ago

youanden commented 10 years ago

I am working with schema that has already been defined and populated (hence profile attributes are not currently possible) and am trying to override the rules() function without changing anything in the vendor folder.

I am using the advanced yii2 beta organization and have attempted a variety of configurations (passing a different identity class), forcing my User model at common/models as well as backend/models to an edited copy of your auth\models\User class with no luck.

I'm excited by the organization of Yii and PHP 5.4s array syntax that would let me write rules like

public function rules()
{
  return [
    ['first_name', 'required']
  ] + parent::rules();
}

Is there a way you know of where I can override your User model class?

Thank you for your time.

robregonm commented 10 years ago

You just need to create a child class... something like:

class User extends \auth\models\User
{
    public function rules()
    {
      return [
        ['first_name', 'required']
      ] + parent::rules();
    }
}

You can create that model in your models folder, and even create your own relations.

Feel free to comment (and contribute :) )

youanden commented 10 years ago

Thank you!