Using attributes and rules from a different model

Hi all,

I just can’t get my head around this.

Say I have a model called Products and another model called spec.

Now, I’ve defined the relations between those two and I want to create a form that will show fields from both models, so upon submit, yii will check the rules from both models - Products and Spec.

How do I do this without redefining Spec rules on Products model?


To this kind of task you need to define a Form Model for this specific form .Where you can define your own validation rules.And when you are trying to save these values in the table then assign them with there specific model and save it.

try to do this… :)

Haa… makes perfect sense! Thanks!

Where would you define the other models for saving? in the controller or in the new Form Model?

Usually i define in the controller file.But you can also define in the model. :)