in yii2 basic template
we can found ContactForm, LoginForm and User in Model directory
my question is
why not use scenario login, contact in User Model
in yii2 basic template
we can found ContactForm, LoginForm and User in Model directory
my question is
why not use scenario login, contact in User Model
for me, it makes the code clear.
User is used to manage user
LoginForm is used to manage login.
mix them up and you have a mess to deal with later.
A model is a set of data. If you are handling different sets of data in different scenarios, then you’d be better create different models.
As for contact page, it has nothing to do with the user model. A sheer guest can send a contact mail through this page.
The set of data we have to handle in this page is:
The title of the message
The body of the message
The email address
The text for the captcha
Do you want to handle these data with your user model? I’m sure you don’t.
And the login page handles only the following data:
The username (login account)
The password
These are the things that you may want to store in your user model. But for user authentication Yii handles them not directly using your user model, but through the IdentityInterface that should be implemented in your user model.