使用Yii2,我正在尝试从数据库中创建一个下拉列表(已经完成),但显示所选值的字段。
示例:
表:
不可思议的
这是我的代码:
型号:
class Imm extends ActiveRecord{
public static function tableName()
{
return 'i10';
}
public function attributeLabels(){
return array(
'N_NUME_IMME' => 'N_NUME_IMME',
);
}
}
控制器:
public function actionImm($id)
{
$model = new Imm(); // envoyer le model sur imm.php
$query = Imm::find(); // trouver le model
$model = $this->loadModel($id);
$imm = Imm::find()->where(['N_NUME_IMME' => $id])->one();
$items = ArrayHelper::map(Imm::find()->all(), 'N_NUME_IMME', 'L_NOM1_COMP');
return $this->render('imm',['imm'=>$model,'imm'=>$imm, 'items'=>$items]);
}
观点:
<h1>Immeuble : </h1>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'layout' => 'horizontal',
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-6\">{input}</div>\n<div class=\"col-lg-6\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<div class="form-group">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?= Html::activeDropDownList($imm, 'N_NUME_IMME',$items, ['class' => 'form-control', 'name' => 'liste_immeubles'])?>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?= Html::submitButton('Chaufferie', ['class' => 'btn btn-primary', 'name' => 'bouton_']) ?>
<?= Html::submitButton('Locaux communs', ['class' => 'btn btn-primary', 'name' => 'bouton_d']) ?>
<?= Html::submitButton('Parking/Amenagements Ext', ['class' => 'btn btn-primary', 'name' => 'bouton_donnees_generales']) ?>
<?= Html::submitButton('Facades/Toitures', ['class' => 'btn btn-primary', 'name' => 'bouton_don']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
<h2>Donnees Generales</h2>
<div class="col-lg-6">
<?= $form->field($imm, 'C_MODE_CHAU')->textInput(['autofocus' => false]) ?>
</div>
<div class="col-lg-6">