Ich habe zwei Modell A und B, in Modell A Formular anfügen Modell B von dynamisch, aber wenn ich auf create button, bekomme ich nicht Modell B Daten in POST.wo ich bin Unrechttuns bitte helfen ..yii2 Daten anhängen durch renderAjax fehlt in Post-Daten
Modell A-Form (Ansicht)
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\web\View;
$script = <<< JS
$.ajax({
type :'POST',
data: {total_form:1},
cache : true,
url : '/stag_str/web/index.php/activities/create',
success : function(data) {
$('.p_scents').append(data);
},
});
JS;
$this->registerJs($script);
?>
<div class="currency-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'currency_name')->textInput(['maxlength' => true,'style'=>'width:150px']) ?>
<div class="p_scents"></div>
<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(); ?>
</div>
Modell A-Controller
public function actionCreate(){
$model = new Currency();
if ($model->load(Yii::$app->request->post())) {
print_r($_POST);exit;
return $this->redirect(['view', 'id' => $model->currency_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Modell B Form, die ich machen würde durch Ajax-Aufruf
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Activities */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="activities-form">
<?php $form = ActiveForm::begin(['id' => 'activity' ]); ?>
<?= $form->field($model, 'activity_name')->textInput(['maxlength' => true]) ?>
<?php ActiveForm::end(); ?>
</div>
Modell Aktion B mit renderAjax
public function actionCreate()
{
$model = new Activities();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->activity_id]);
} elseif (Yii::$app->request->isAjax){
return $this->renderAjax('_form', [
'model' => $model,
]);
}
}
ich nicht Modell B Formulardaten beim Speichern Modell Form A bin immer ..
Update Sie ähnliche Modelle in Frage hinzufügen, Controller/Aktion und Ansicht Code .. – scaisEdge
können Sie bitte überprüfen Sie die Anfrage, wenn es Ajax Aufruf mit print_r (Yii :: $ app-> Anfrage-> isAjax); Ausfahrt(); Du musst wahr werden. –
Setzen Sie diesen Code in actionsCreate() für Model B. –