I have a form page that one of the field is named type
and it's enum('lost', 'found')
and in this form, I want that field to be a dropdown list that only has these two options lost
and found
.
one of the suggested options was using this in view
<?= $form->field($model, 'type')->dropDownList(
$items,
['prompt'=>'']
and this in the controller
$items = ArrayHelper::map(Ads::find()->all(), 'id', 'type');
but as you know it's just using the inserted data in the db and if I click on the dropdown list, it'll load all the lost and found options that are in the db.
Is there any way to tell yii to use the db structure and rules instead of the datas?
I have to point out that in the model I couldn't find any rules that is indicating the enum part, Is it ok? Why is it like this?
I used Gii for creating these.
public function rules()
{
return [
[['type', 'explanation', 'image', 'cost', 'province_id', 'address'], 'required'],
[['type', 'explanation', 'image', 'address'], 'string'],
[['cost'], 'integer'],
[['province_id'], 'string', 'max' => 20],
[['province_id'], 'exist', 'skipOnError' => true, 'targetClass' => Province::className(), 'targetAttribute' => ['province_id' => 'name']],
];
}