Yii save data to different tables
I am new to Yii. I need to save data collected from a single form to three different tables. So my dou开发者_JAVA百科bts are
How can I design the Model class (CformModel or CActiveRecord)??
How to design the view??
In Controller how can I save the data to different tables??
I need to manually validate some vales like md5 hash etc
you need to create three models. And use according model fields and save all three models.
In Yii one table - one model.
In your controller: saving your different models for different tables will look like:
$modelB=new Addresses;
$modelB->attributes=$sess['addresses'];
$modelB->save();
$modelC=new TenQs();
$modelC->attributes=$sess['tenqs'];
$modelC->save();
To render multiple models to one form you just keep listing the models in the render statement.
$this->render('create',array('modelB'=>$modelB,'modelC'=>$modelC));
That would work in your controller. This example assumed Active Record.
精彩评论