Answer the question
In order to leave comments, you need to log in
Field visibility in yii2?
Connoisseurs, tell me, the whole brain is broken. There is a controller, it has an action with parameters, and the parameters are as follows:
Individual
Legal
Ip
And depending on the parameter, a form with the fields you need should appear. And the form is one where all the fields for three different options are listed. Some of the fields are shared.
How can you revise something like this?
So far, it comes to mind only through scenarios, such as scenarios:: fizik, and there already indicate the visibility of the fields and validation.
Maybe there are other ways?
Answer the question
In order to leave comments, you need to log in
This, it seems, needs to be divided into different actions so that there are no troubles with access control.
And at the expense of forms, then follow the path of the standard template - make your own model for each form. If you really want to generalize the general part, then let these 3 models be inherited from one common one (I would not do that, but it depends heavily on the amount of "common"). The benefit is that you avoid a bunch of conditional expressions this way, making your code more readable and easier to edit.
P.S. Not an expert, but yes I know something.
Scripts are the best for this purpose. In the form, you can make conditional comments, like:
Or create several field sets in different files, and include them in the same way by condition.
Or, using the same scripts, render different forms in the controller.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question