Reputation: 8695
At the begging of the view file I am loading model:
use app\models\Countries;
And a bit down in the code I am trying to create dropdown (model is generated via gii):
<?php
echo $form->field(Countries::find()->all(), 'Country')
->dropDownList(
['prompt'=>'Select Country']
);
?>
I am getting this error:
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
What is going on here?
Upvotes: 2
Views: 1304
Reputation: 133360
Try this
<?= $form->field($model, 'your_field')->dropDownList( ArrayHelper::map(Country::find()->all(), 'country_id', 'Country_description'),['prompt'=>'']) ?>
change country_id, your_field and country_description
for your need
Upvotes: 2