Damodaran
Damodaran

Reputation: 11047

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 doubts 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

Upvotes: 2

Views: 6415

Answers (2)

k to the z
k to the z

Reputation: 3185

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.

Upvotes: 2

RusAlex
RusAlex

Reputation: 8575

you need to create three models. And use according model fields and save all three models.

In Yii one table - one model.

Upvotes: 7

Related Questions