How to implement the following Yii code to Yii2:
<?php
echo $form->dropDownList($model,
'project',
$model->getProjectOptions(),
array('empty' => 'Empty string')
);
?>
Why not
<?
dropDownList($model,
'project',
$model->getProjectOptions(),
array('prompt'=>'Empty string')
); ?>
Here is old CHtml https://github.com/yiisoft/yii2/blob/master/framework/yii/helpers/base/Html.php
Can find there if you need something more.
Use the following code to get the dropdownlist in yii2 friend.
<?php
//use app\models\Country;
$countries=Country::find()->all();
//use yii\helpers\ArrayHelper;
$listData=ArrayHelper::map($countries,'code','name');
echo $form->field($model, 'name')->dropDownList(
$listData,
['prompt'=>'Select...']);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With