There is a database, it has two tables:
- Table1
- Table2
In Table2 there are lines: id и Name .
The site has two pages:
- Home page
- Add page
On the Add page there is a form in which there is input, with the help of this form I add entries to table2. With this page everything is OK.
Task with the main page. There is a form, what is its essence: I get the first entry from the table2 table, for example, there will be Name1. Here is the form code on Yii2
<?php foreach($allNameEx as $nameEx) : ?> <?= $form->field($model, $nameEx['name'])->checkbox() ?> <?php endforeach; ?> <div class="form-group"> <?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?> </div> $model is $model = new form();
$allNameEx is an array that retrieves all Name records from table2.
This code would work, but when creating a form on the page, there is a form model file in which you need to add variables the same as in the input form. If <?= $form->field($model, $nameEx['name'])->checkbox() ?> It will be, for example <?= $form->field($model, 'Name1')->checkbox() ?> , then in the form model, respectively, there must be a variable public $ Name1. So the question is how to add these variables to the form model?