Yii2のdropDownListで選択した値($ model->属性)を取得していません。何が間違っている可能性がありますか?おかげYii2のdropDownListの値を取得する方法は?
これは、ビュー上に配置されているコードです:
public function actionTest()
{
$model = new TestForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->insertTest();
return $this->renderAjax('test', ['model' => $model]);
} else {
return $this->renderAjax('test', ['model' => $model]);
}
}
:
$command = $connection->createCommand('SELECT att1
FROM table
ORDER By table_id ASC');
$rows = $command->queryAll();
$command->execute();
$listData = ArrayHelper::index($rows, null, 'table_id');
はその後、同じビュー上で、私はこれはコントローラである
<div class="row">
<div class="col-lg-9">
<?php Pjax::begin(['enablePushState' => false]); ?>
<?php $form = ActiveForm::begin(['id' => 'test-form', 'options' => ['data-pjax' => true]
]); ?>
<?= $form->field($model, 'attribute')->dropDownList($listData, ['prompt'=>'List of attributes.']); ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'test-button']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</div>
</div>
$ listDataプロパティを呼び出します
モデルは$ attributeの定義を持ち、insertTest()は$ attributeの値を使って関数を呼び出す関数ですDB上に移動します。あなたは一次元配列を必要とするので、あなたの
あなたは '$ model'をどのように開始するのかを示す必要があります。おそらくコントローラーにあり、POST/GETリクエストからロードされます。 – lubosdz