Hi guys i am new to yii2
so i know i am asking stupid question
but i could not figure out the solution
i have 2 tables
Organiser
Event
Organiser is logged in using the username and password
and he/she can create event
not there are couple of fields are almost same in Organiser and Event
so rather than asking them again to fill it up
i want to check the organiser_id on Event create action and send those value to
Create form
But i dont know how to do it
Do i need to pass 2 models to the create form
1 with organiser model and 2nd event model
or i can do it some other way
ok here is what i have done until now
public function actionCreate()
{
$model = new Event();
if ($model->load(Yii::$app->request->post())) {
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model2 = new User();
$model2 = $this->findModel2(Yii::$app->user->id);
return $this->render('create', [
'model' => $model,
'model2' => $model2
]);
}
}
Until now its good
But how can i check on the view form that the form is Create form or update form
It the form is create form than only i want to set the value from $model2
If its update form than it should take values from $model
How can i check that on form
here is code of my form
<div class="event-form">
<span class="label label-danger">Fields marked with * are mandatory</span>
<p></p>
<?php $form = ActiveForm::begin([
'options' => [
'id' => 'create-event-form'
]
]); ?>
<?= $form->field($model, 'interest_id')->dropDownList(
ArrayHelper::map(Areaintrest::find()->all(),'id','area_intrest'),
['prompt'=> 'Select Event Category']
) ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'description')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
]) ?>
<?= $form->field($model, 'location')->textInput(['class' => 'placepicker form-control']) ?>
<di"form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-danger' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>