在保存显示三次的表格字段时,我遇到了问题。无法保存保存在文本字段中的唯一值。请有人指导我正确的答案。
查看代码:
<h2>List of Documents</h2>
<table class="table">
<?php foreach($formlist as $item) { ?>
<tr>
<td><?= $form->field($model, '['.$item->id.']value')->radioList(['yes'=>' yes','no'=>' no'])->label($item['title']); ?></td>
</tr>
<?php } ?>
</table>
控制器代码:
public function actionCreate()
{
$model = new Form();
$forminfo = new Forminfo();
$forminfo->id = $model->forminfo_id;
/*$sql = 'SELECT * FROM formlist ORDER BY id ASC';
$db = Yii::$app->db;
$formlist = $db->createCommand($sql)->queryAll();*/
// same of ->
$formlist = Formlist::find()->orderBy(['id'=>SORT_ASC])->all();
if ($forminfo->load(Yii::$app->request->post()) && $model->load(Yii::$app->request->post())) {
$forminfo->save(false); // skip validation as model is already validated
$model->forminfo_id = $forminfo->id; // no need for validation rule on user_id as you set it yourself
$model->save(false);
Yii::$app->getSession()->setFlash('success', 'You have successfully saved your data.');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
'forminfo' => $forminfo,
'formlist' => $formlist,
]);
}
}