In Yii multimodel form we just used actionCreate() to create the form of two models in a single view.Ok everything is fine upto here.But when we will update the two models in a single view of multimodel how the models will be defined here? Let me give you one example.Just think the database is just like this
=== Project ===
id
task_id(FK)
description
=== Task ===
id
name
description
So In actionCreate() of the project controller,the code will be something like this
public function actionCreate()
{
$model=new Projects;
$tasks=new Projects;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Projects'],$_POST['Tasks']))
{
$model->attributes = $_POST['Projects'];
$tasks->attributes = $_POST['Tasks'];
$valid = $model->validate();
$valid = $tasks->validate();
if($valid)
{
$model->save(false);
$tasks->save(false);
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
'tasks'=>$tasks,
));
}
Now here the both models are ready for create. So what to do in actionView()
and actionUpdate()
?How to declare the both models?Any help and suggestions will be highly appriciable.