I have searched the web far and wide for a solution to this problem. I already know the Yii2 dropdown way is this:
<?php
use yii\helpers\ArrayHelper;
use backend\models\Standard;
?>
<?= Html::activeDropDownList($model, 's_id',
ArrayHelper::map(Standard::find()->all(), 's_id', 'name')) ?>
But I want to make the dropdown without the $model
... Is there ANY way to do this?
Thank you in advance!
You can also use
Html::dropDownList()
<?= Html::dropDownList('s_id', null,
ArrayHelper::map(Standard::find()->all(), 's_id', 'name')) ?>
See Yii Manual
You can also use this:
public function getAll()
{
$get = Standard::find()->all();
$result = ArrayHelper::map($get, 'id', 'name');
return $result;
}
Then dropdown:
<?= Html::dropDownList(Standard::getAll(), ['prompt' => '--- select ---']) ?>
This will solve your error.
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