我有一个活动表格的下拉列表我正确显示数据但是当我想插入下拉列表中所选值的值时,该值为空。
在我的控制器中:
$model = new AjoutRessourceForm();
if ($model->load(Yii::$app->request->post()) && $model->validate())
{
if ($ressource = $model->addRessource())
{
return $this->redirect(['form/ressource']);
}
}
$sql = "select idEtatRessource, nomEtatRessource from etat_ressource";
$command = $connection->createCommand($sql);
$data = $command->queryAll();
$etats = ArrayHelper::map($data, 'idEtatRessource', 'nomEtatRessource');
return $this->render('/form/newRessource', ['model' => $model, 'etats' => $etats, 'types' => $types]);
在我看来:
<?= $form->field($model, 'idEtatRessource')->dropDownList($etats) ?>
在模型中:
$histEtatRessource = new HistoriqueEtatRessource();
$histEtatRessource->idRessource = $this->idRessource;
$histEtatRessource->idEtatRessource = $this->idEtatRessource;
if ($ressource->save() && $histEtatRessource->save())
{
return $ressource;
}
我有一个IntegrityException,因为$this->idEtatRessource
的值为null(我的数据库中的主键)
谢谢!
--- --- EDIT
当我通过$_POST['idEtatRessource']
代替$this->idEtatRessource
时,它工作,我不知道为什么!请帮忙;)
答案 0 :(得分:0)