YII2 form listBox

Model

class Service extends \yii\db\ActiveRecord { public function getDataItems() { return ArrayHelper::map(self::find()->all(), 'id', 'name'); } }

Views

<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'service_id')->listBox($service->getDataItems(), ['maxlength' => 255]) ?> <?php ActiveForm::end(); ?>