A
A
Arman2017-01-28 16:55:16
Yii
Arman, 2017-01-28 16:55:16

Yii2 when to create separate form model and when to inherit?

DD.
The advanced YII2 application has a registration form and a password reset form , both forms do not inherit the User model and have their own independent validation rules, I don’t like that validation rules are scattered around the code for some fields, for example, you need to change the minimum number of characters in the password , in one place they will change in another they can forget. Then it is necessary to write down the rules of the User model and inherit the forms from it? But then the forms get too many accesses, override methods, properties and the model itself grows terribly, the option proposed by the yii developers is more attractive. Then can the rules be stored in the statistical properties/methods of the main model (User)? Then all models will remain autonomous and they will more/less have common rules.
What is more or less the right way for YII developers?
I know about the script, but I don’t like this approach a bit, I want autonomy for simple forms / actions.
Well, in general, should the validation rules for all fields / attributes be stored in the main model? Or is it better to carry the rules into the form models, as shown in the example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-01-28
@Arik

For registration, login and password reset - different rules can be. In addition, a different set of attributes.
In addition, if you inherit these forms from the USer model, all methods of the user model will become available in them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question