public function up() { $this->createTable(\app\models\Author::tableName(), ['id' => Schema::TYPE_PK, 'firstname' => Schema::TYPE_STRING . ' NOT NULL', 'lastname' => Schema::TYPE_STRING]); $authors = [['firstname' => 'Harper', 'lastname' => 'Lee'], ['firstname' => 'Tom', 'lastname' => 'Rath'], ['firstname' => 'Roger', 'lastname' => 'Priddy']]; foreach ($authors as $a) { $author = new \app\models\Author(); $author->attributes = $a; $author->save(); } }
?> <?php echo $form->field($modelBook, 'title')->textInput(); echo $form->field($modelBook, 'alias')->textInput(); echo $form->field($modelBook, 'description')->textarea(); echo $form->field($modelBook, 'photo')->textInput(); ?> <div class="row"> <div class="col-md-6"> <h4>Укажите авторов книги</h4> <? $dataProvider = new yii\data\ActiveDataProvider([ 'query' => app\models\Author::find(), 'pagination' => false, 'sort' => false, ]); echo yii\grid\GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', 'name', [ 'class' => yii\grid\CheckboxColumn::class, 'name' => 'authors', 'checkboxOptions' => function ($modelAuthor) use ($authorIds) { $options = ['value' => $modelAuthor->id]; /** @var \app\models\Author $modelAuthor */