0

How do I get a value and make it appear on a dropDownlist on yii2

For example I have 2 models which is hotel guest and service request. I wanna get the hotelguest_id value from its model and store it on a dropdown on the service request.

Similar like this.

<?= $form->field($model, 'hotelguest_id')>dropDownList(yii\helpers\ArrayHelper::map(hotelguest_id::find(->all(), 
'id', 'id')) ?>
noobkoder
  • 87
  • 18

1 Answers1

2

I already figured it out

By using

use app\models\Hotelguest;
use yii\helpers\ArrayHelper;

<?= $form->field($model, 'hotelguest_id')->dropDownList(ArrayHelper::map(Hotelguest::find()->all(), 
 'id', 'id'), ['prompt' => 'Select Hotel Guest ID']); ?>
vishuB
  • 4,173
  • 5
  • 31
  • 49
noobkoder
  • 87
  • 18