public static function getFieldTypes() { $array = []; foreach (FieldType::find()->all() as $item) { $array[$item['id']] = $item['name']; } return $array; }
/** * @return \yii\db\ActiveQuery */ public function getFieldType() { return $this->hasOne(FieldType::className(), ['id' => 'type']); }
<div class="field-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'system_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'type')->dropDownList(\backend\models\FieldType::getFieldTypes()); ?> <?php echo $form->field($model, 'length')->textInput(); ?> <?php echo $form->field($model, 'default')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'table_id')->dropDownList(\backend\models\Table::getTablesList()); ?> <div class="form-group">