L
L
Lev K2016-05-13 09:45:43
Yii
Lev K, 2016-05-13 09:45:43

How in yii2 is data written from post to the model?

I don't understand how this design works.

if (Model::loadMultiple($infoModels, Yii::$app->request->post())) { ... }
или
if ($model->load(Yii::$app->request->post())) { ... }

If you use a field in the view, then everything is more or less clear, it indicates the model to which the field belongs and when submitting the form, the controller inserts the necessary data into the model
<?= $form->field($model, 'name')->textInput() ?>
. But when generating a page using jquery (dynamic page), I have a problem. It seems to describe the structure the same as yii creates it, but the data is not saved. Namely, only the first model is stored in loadMultiple, and the rest are not. Maybe there is some kind of manual (or a few reminders) how to write html manually for yii?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2016-05-13
@Leffken

First, see what goes from the form to the server through the debug panel in the browser.
Secondly, look at the examples of working with load and loadMultiple in the documentation, or in other extensions (look on github).
In general, there is not much difference how to display input - through yii, or "naked" html. The main thing is that the name field is filled in correctly. Accordingly, for loadMultiple, an array must be specified in your name. For example, you fill out a form with an application, there may be several services in the application. Example name="Bid[servicesIds][]". As a result, on the server you $_POST['Bid']['servicesIds']will have an array of service ids.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question