The database has a Name field (in which the names of future input are recorded). In the model, I pull out all the Name that is and they are written to the array. In the controller I transfer this array to views. In the views / index file, you need to make a form in which there will be a checkbox with the names that they will receive from Name.

//$nameRecordsCount - это количество всех Name в базе //$allNameEx - это массив с id и Name // То есть $allNameEx[$i]['name']; вернет например name1; //И вот я тут хочу передать имя в строку после, $model, но я получаю ошибку //Attribute name must contain word characters only. <?= $form->field($model, 'date')->widget(yii\jui\DatePicker::className(),['dateFormat' => 'yyyy-MM-dd'])?> <?php for ($i = 0; $i < $nameRecordsCount; $i++) { ?> <?php $formName = (string)$allNameEx[$i]['name'];?> <?= $form->field($model, "$formName")->checkbox() ?> 

Why and how to solve?

ps sorry for the quality of the question, I do not know yet how to edit the pasted code.

    1 answer 1

     <?php foreach($allNameEx as $nameEx) : ?> <?= $form->field($model, $nameEx['name'])->checkbox() ?> <?php endforeach; ?> 
    • This is a good option without for, but I still get a throw new InvalidParamException ('Attribute name must contain word characters only.'); - Fitstd
    • The error speaks for itself, make var_dump ($ allNameEx) or print_r ($ allNameEx) and show the result - Alexandr Kalashnikov
    • Array ([0] => Array ([name] => Name 1 [id] => 1) [1] => Array ([name] => Name 2 [id] => 2) [2] => Array ([name] => Name 3 [id] => 3) [3] => Array ([name] => Name 4 [id] => 4) [4] => Array ([name] => Name 5 [id] => 5)) print_r ($ allNameEx); - Fitstd
    • I understand that it swears at the $ symbol, and in throw new there is a ban on $ - Fitstd
    • one
      How do you imagine the name of the attribute / property class / field in the database with a space? - Alexandr Kalashnikov