Long tormented by the question whether it was necessary to create such a model Singup(like
this), if you can use a basic User model:
public function actionSignup()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$model->setPassword($model->password);
if ($model->save()) {
if (Yii::$app->getUser()->login($model)) {
return $this->goHome();
}
}
}
return $this->render('signup', [
'model' => $model,
]);
}
Instead of:
public function actionSignup()
{
$model = new SignupForm();
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->signup()) {
if (Yii::$app->getUser()->login($user)) {
return $this->goHome();
}
}
}
return $this->render('signup', [
'model' => $model,
]);
}
For example some forms, but they all use the same model table in the database. The only difference is that in each form its own set of fields. Solved this problem using scripts.
Or all the same to alter at several models, one model in one form? - Dion77 commented on June 14th 19 at 19:00
>The only difference is that in each form its own set of fields
Try to consider of the forms and fields, and from the business logic - for what purpose do you serve these forms, and which business processes need to happen.
Model forms are used for handling user data and providing additional information when needed. To save to the database was only valid data. One request - one form of model which should return a valid dataset.
> Or all the same to alter at several models, one model in one form?
It makes no sense to redo it until you come understanding what you need to alter. If you do not come understanding on a particular project, then the norms and not have to redo anything. - Brett.Haley commented on June 14th 19 at 19:03
The first - return call(name and phone), the second - a short message(name, email and message), and third different parameters of the goods(name, route, and mail is always there).
The project was originally in yii1, all piled up in one heap, a lot of if else to resolve where and what to insert. Broke into several actions with different scenarios to smaller checks and not getting confused. But there was one common. Rather for backend and frontend are two separate and one parent, which contains General data for backend and frontend. In the frontend of the model is the validation in action, what is the script to connect, and I think that is crap. - Dion77 commented on June 14th 19 at 19:06
What actions occur after filling each form? Just saved that the user navvodili and all, or they still generate some processes?
If validation deal with the relevant request form and the appropriate services there is no need to produce copies of the AR model. its task is only to store data, and display data.
Although if you have something like a landing page with the order call feedback and a calculator of the goods, and the special development and support of the project are not expected, can not bother. - Brett.Haley commented on June 14th 19 at 19:09
What forms should Express the subject area? Shape this is only the display layer, there may occur only rudimentary data validation that is not tied to the business logic. This can be compared with front forms validation before sending to SPA.
There are different implementations, but in most cases it is recommended(including in the dock yii): the model should include validation of business rules implementing business logic subject area.
AR is just a pattern which combines the business entity and the repository(the object responsible for storing data).
In my opinion it is not necessary to advise something not good. People can come astray. In the forms to keep the business logic is utter nonsense, the form is a representation.
Of course maybe I misunderstood you. - Davonte.Renner commented on June 14th 19 at 19:12
yiiframework.ru/forum/viewtopic.php?p=212604#p212604
https://github.com/yiisoft/yii2/commit/35f7c61f776...
>>in the model should include validation of business rules implementing business logic subject area.
But the business model !== AR-model, the model is not a single class. - Brett.Haley commented on June 14th 19 at 19:15