Hi i have problem with using two module in one form
This is my problem
i try add input using club model
this is mysql Tables
tbl_contestant
-id
-name
-surname
-age
-club_id
tbl_club
-id
-name
this is my contestantController actionCreate
public function actionCreate()
{
$m_contestant=new Contestant;
$m_club=new Club;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Contestant']) && isset($_POST['Club']))
{
$m_contestant->attributes=$_POST['Contestant'];
$m_club->attributes=$_POST['Club'];
if($m_contestant->save())
$this->redirect(array('view','id'=>$m_contestant->id));
}
$this->render('create',array(
'm_contestant'=>$m_contestant,
'club'=>$club,
));
}
hello ameth69 you are using two models in your controller and creates two objects for each one and renders form contains for both models and when the form get submitted you are always trying to save contestant only so it makes the problem because club id in the contestant table refers to id of the club table. so if you save contestants first you will get these error only. so that club must be saved before contestant so that you can get club_id for contestant like this $m_contestant->club_id = $m_club->id; and save the $m_contestant->save()