简体   繁体   English

从另一个模型Yii2获得价值

[英]Getting a value from another model Yii2

How do I get a value and make it appear on a dropDownlist on yii2 我如何获得一个值并使它出现在yii2的dropDownlist上

For example I have 2 models which is hotel guest and service request. 例如,我有2个模型,分别是酒店客人和服务请求。 I wanna get the hotelguest_id value from its model and store it on a dropdown on the service request. 我想从其模型中获取hotelguest_id值,并将其存储在服务请求的下拉列表中。

Similar like this. 像这样。

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

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']); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM