Daten auf 2 Tabellen aus einzelnen Form und Controller einzufügen ist meine Seite, wie dies in yii2
Fragen/create.php
<?php $form = ActiveForm::begin(); ?>
<br><br><br>
<?= $form->field($model, 'question')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'topic')->textInput(['maxlength' => true]) ?>
<?= $form->field($model1, 'askid')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end();
askid das Feld in einer anderen Tabelle ist stellefragen
erstellen questioncontroller
public function actionCreate()
{
$model = new Questions();
$model1 = new Askquestions();
//$model1 -> load(Yii::$app->request->post());
if ($model1->load(Yii::$app->request->post())) {
//$model->user_id=Yii::$app->user->identity->id;
if($model1->save())
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model, 'model1' => $model1,
]);
}
}
Ich habe Modell und Crud für askquestions t erzeugt Lage und auch Klasse in der Steuerung und Ansichtsseite aber das Einfügen von Daten ist nicht in der Tabelle enthalten sind, was die Art und Weise,
Mögliches Duplikat von [Yii2-Mehrfachformularen in einer einzigen Aktion] (http://stackoverflow.com/questions/28567736/yii2-multiple-forms- in-a-single-action) –