开发者

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

  1. How can I design the Model class (CformModel or CActiveRecord)??

  2. How to design the view??

  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜