1

I am writing application in Yii2 framework. It has User model used by Controllers. This model has these methods:

  • classic methods for database entity management
  • methods for management files of user
  • authentification and authorisation methods

I think, this class violate Sigle Responsibility Principle (SRP), becouse it has at least 3 reasons to change. Its functionality could also split into separate classes (models/components/something else). So I thought to redesign this and apply something, what can fix this. But I don't know how can I do this by using Yii2 and not to violate MVC principle. The best solution could be use som Yii2 features. Should I split this one model to more components or even models? Should I redesign my database and normalize my user table? What could be the best possible solution?

kennySystemExit
  • 329
  • 2
  • 5
  • 22
  • [The Model in MVC is a layer, not a class or object](http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models/14045514#14045514) – topher Aug 24 '15 at 07:24
  • Ok, I mean that I have class User which exted classs ActiveRecord which extends BaseActiveRecord which extends Model... Therefore I am talking about model(s). – kennySystemExit Aug 24 '15 at 07:48

1 Answers1

3

Your application has a yii\web\User class. To quote the guide, User is the class for the "user" application component that manages the user authentication status. It has identity attribute that is your ActiveRecord descendant (your app\models\User class).

So app\models\User implements IdentityInterface, but that is just a set of getter methods to map yii\web\User's attributes like access token to relevant attributes of your model.

Lastly, app\models\User has nothing to do with managing user files. If you're talking about user roles, which can be stored as files, yii\rbac\PhpManager is used for that purpose.

To summarize:

  • database entry management is implemented in app\models\User
  • authentication (finding out who is who) is implemented in yii\web\User
  • authorization (finding out who can do what) is implemented in yii\rbac\PhpManager or another manager or access control lists
  • user files are managed elsewhere
Beowulfenator
  • 2,262
  • 16
  • 26