übergeben Ich habe diese Art von Problem. Ich habe einen Eingabetext, der eine Radiovorlage enthält.yii2 Wert von Sicht zu Controller
Das Problem ist, dass ich den Wert des Radios erhalten möchte, wenn ich es überprüfe und es in das Datenbankfeld speichere.
Meine Idee ist es, eine Variable aus dem Modell zu erstellen, aber ich kann den Radio-Wert nicht an diese Variable übergeben, wenn ich sie speichere.
bitte helfen Sie mir, ich bin dabei fest.
hier die Bilder von Ansicht:
Controller-Aktion:
public function actionCreate()
{
$model = new QbQuestion();
if ($model->load(Yii::$app->request->post())) {
$answer = $model->answer;
$model->$answer;
$model->save();
return $this->redirect(Url::to(['qb-question/index']));
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
Ausblick:
<div class="qb-question-form">
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-4',
'offset' => 'col-sm-offset-4',
'wrapper' => 'col-sm-8',
'button' => 'col-sm-8',
'error' => '',
'hint' => '',
],
],
]); ?>
<?php echo $form->errorSummary($model); ?>
<?= $form->field($model, 'q_cat')->dropDownList(
ArrayHelper::map(QbCategory::find()->all(), 'id', 'category'),
[
'prompt' => 'Select Category'
]) ?>
<?= $form->field($model, 'q_date')->dropDownList(
ArrayHelper::map(QbDate::find()->asArray()->all(), 'id',
function($model, $defaultValue) {
return $model['month'].' '.$model['year'];
}),
[
'prompt' => 'Select Date'
]) ?>
<?php echo $form->field($model, 'question')->textarea(['rows' => 5]) ?>
<?= $form->field($model, 'q_c1', [
'inputTemplate' => '<div class="input-group"><span class="input-group-addon">'.
Html::radio('answer').'</span>{input}</div>',
]); ?>
<?= $form->field($model, 'q_c2', [
'inputTemplate' => '<div class="input-group"><span class="input-group-addon">'.
Html::radio('answer').'</span>{input}</div>',
]); ?>
<?= $form->field($model, 'q_c3', [
'inputTemplate' => '<div class="input-group"><span class="input-group-addon">'.
Html::radio('answer').'</span>{input}</div>',
]); ?>
<?= $form->field($model, 'q_c4', [
'inputTemplate' => '<div class="input-group"><span class="input-group-addon">'.
Html::radio('answer').'</span>{input}</div>',
]); ?>
<?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
</div>
Dank im Voraus.
Könnten Sie bitte Ihren Code schreiben, nicht nur ein Bild davon? Und das Bild wäre besser in die Frage eingefügt! Es macht die Dinge lesbarer! Thnks –
Entschuldigung im neuen zu dieser site.my Code ist das selbe auf diesem Bild. Ich habe versucht, vom Controller zu erstellen, um es zu speichern, aber es hat nicht funktioniert. Mein Controller-Code sieht so aus: öffentliche Funktion actionCreate() { $ model = new QbQuestion(); if ($ model-> load (Yii :: $ app-> Anfrage-> Post())) { $ answer = $ model-> answer; $ modell -> $ antwort; $ model-> save(); return $ this-> Umleitung (Url :: to (['qb-question/index']))); } else { Rückgabe $ this-> renderAjax ('create', [ 'Modell' => $ Modell, ]); } } – top
Großartig! Jetzt müssen Sie nur den Code kopieren und einfügen, den Sie im Bild haben, das Bit, das mit '$ form-> field' beginnt. –