在视图文件的请求下,我正在加载模型:
use app\models\Countries;
在我试图创建下拉列表的代码中有点下降(模型是通过gii生成的):
<?php
echo $form->field(Countries::find()->all(), 'Country')
->dropDownList(
['prompt'=>'Select Country']
);
?>
我收到此错误:
PHP Fatal Error – yii\base\ErrorException
Call to a member function formName() on a non-object
1. in /home/sasha/Documents/Scopic/Stokkee/project/svn/vendor/yiisoft/yii2/helpers/BaseHtml.php at line 1975
这里发生了什么?
答案 0 :(得分:2)
试试这个
<?= $form->field($model, 'your_field')->dropDownList( ArrayHelper::map(Country::find()->all(), 'country_id', 'Country_description'),['prompt'=>'']) ?>
根据您的需要更改country_id, your_field and country_description