I currently have quite a complex object / model hierachy. The system being designed is for Solar Power installers and consists of the following model hierachy:
- Project has:
[indent]
-
Customer
-
Photovoltaic System has:
[indent] - Installation Site / Location - Power Inverter - Misc Components - Photovoltaic Arrays has: [indent] - Photovoltaic Modules [/indent] [/indent]
[/indent]
The basis of the system is a photovoltaic solar system has multiple arrays which are made up of multiple photovoltaic modules ( solar panels ).
The main user interaction point is going to be based around the Project controller. Where the user goes through a stepped process that creates a project / pv system.
My Question: Is there a better way to init the model inheritance / encapsulation hierarchy described above in the controller then i am currently doing… see below? any tips are welcome. Best Practices is the name of my game. GO YII!
below is code from Project controller
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
// define and init model hierachy
$model = new project;
$model->customer = new customer;
$model->system = new system;
$model->system->site = new site;
$model->system->site->address = new address;
$model->system->site->location = new location;
$model->system->pv_arrays[0] = new pv_array;
//$model->system->pv_arrays->modules = new component;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['project']))
{ print_r($_POST);exit;
$model->attributes=$_POST['project'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}