M
M
Marcel G.2016-06-12 21:47:54
Yii
Marcel G., 2016-06-12 21:47:54

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

3 answer(s)
N
Nikita, 2016-06-12
@bitver

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.

D
Dmitry Kim, 2016-06-13
@kimono

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.

V
vyachin, 2016-06-15
@vyachin

the script is rather used for the external environment, for example, one script will be for the admin and the other for the user, and here the task is an order of magnitude easier to solve www.yiiframework.com/doc-2.0/yii-validators-valida...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question