Reputation: 411
public function actionEvent()
{
$event= new Events();
$address=new Addresses();
if($event->load(yii::$app->request->post()) && $event->save() && $address->load(yii::$app->request->post()) && $address->save())
{
echo $event->name;
return $this->render('sucess',['event'=>$event]);
}
else{
return $this->render('event',[
'event'=>$event,
'address'=>$address,
]);
}
}
I don't get the record that i have posted in view form ,i get the null in database.why?
Upvotes: 3
Views: 82
Reputation: 133400
I think you should indicate the name of the form element you want load inside the model
Given that the yii2 load documentation
public boolean load ( $data, $formName = null )
The form name to use to load the data into the model. If not set, formName() is used.
And in this case the form-name don't match the model
try this way
if($event->load(yii::$app->request->post('event')) && $event->save() && $address->load(yii::$app->request->post('eddress')) && $address->save())
or you should get the value from
load($_POST['event'])
load($_POST['address'])
and the assign properly for your propose.
Upvotes: 2