Yii2의 dropDownList에서 선택한 값 ($ model-> attribute)을 가져 오지 않고 있는데, 무엇이 잘못 될 수 있습니까? 감사합니다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');
그런 다음 같은보기에 나는 $되는 listData에 전화
<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>
이 컨트롤러입니다
모델은 $ attribute의 정의를 가지고 있으며, insertTest()는 $ attribute의 값을 que로 사용하는 함수이다. DB에. 당신이 1 차원 배열을 필요로하기 때문에 당신의
'$ model'을 시작하는 방법을 보여줘야합니다. 아마 컨트롤러 및 POST/GET 요청에서로드 ..? – lubosdz