Forms Yii2-从数据库结构中创建下拉列表,而不是在数据库中插入数据

Forms Yii2-从数据库结构中创建下拉列表,而不是在数据库中插入数据,forms,yii2,gii,Forms,Yii2,Gii,我有一个表单页面,其中一个字段名为type,它是enum('lost','found'),在这个表单中,我希望该字段是一个下拉列表,只有这两个选项lost和found 建议的选项之一是在视图中使用此选项 <?= $form->field($model, 'type')->dropDownList( $items, ['prompt'=>''] $items = ArrayHelper::map(Ads::find()-&

我有一个表单页面,其中一个字段名为
type
,它是
enum('lost','found')
,在这个表单中,我希望该字段是一个下拉列表,只有这两个选项
lost
found

建议的选项之一是在视图中使用此选项

 <?= $form->field($model, 'type')->dropDownList(
            $items,
            ['prompt'=>'']
$items = ArrayHelper::map(Ads::find()->all(), 'id', 'type');  
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']],
    ];
}  
但正如您所知,它只是使用数据库中插入的数据,如果我单击下拉列表,它将加载数据库中的所有丢失和找回选项。
有没有办法告诉yii使用db结构和规则而不是数据

我必须指出,在模型中,我找不到任何指示枚举部分的规则,可以吗?为什么会这样?
我使用Gii创建这些。

 <?= $form->field($model, 'type')->dropDownList(
            $items,
            ['prompt'=>'']
$items = ArrayHelper::map(Ads::find()->all(), 'id', 'type');  
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']],
    ];
}  

当一个文件类型是enum并从gii生成crud时,yii会自动在表单中生成这种下拉列表

<?= $form->field($model, 'type')->dropDownList([ 'lost' => 'Lost', 'found' => 'Found', ], ['prompt' => '']) ?>

这不是gii创造的,这是我为此所做的。Gii的创建方式与正常方式相同。如下所示:
您确定字段“type”是枚举数据类型吗?是的,但正如我所说,我不明白为什么在模型中没有与枚举部分相关的内容。我已经在模型中发布了规则。@阿米尔,很奇怪,我会检查。@阿米尔我在用户表中添加了类型字段并生成了一个crud,我可以看到这个dorpdown代码:
由Gii生成。