Two Models In One Form

Hi,

I want to use two models in one form. I am following this tutorial.

Everything is fine till model and controller. Now I want to create the view file which will display the fields from both models.

I am trying to use "$form->labelEx". Its not working. Can anybody help me creating this form.

Dear,

i m facing same problems…but i have two models and one cgridview…if you have any solution plz tell me.

for your ference plz visit http://www.yiiframework.com/wiki/218/how-to-use-single-form-to-collect-data-for-two-or-more-models-cactiveform-and-ajax-validation-edition/

Hi Mohsin Ali,

consider that $form->labelEx() take the name to display from the function attributeLabels() in the model passed as first argument. So if you call, for example:




echo $form->labelEx(User::Model(), 'name');



you should have the definition of the label for "name":




class User extends CActiveRecord

{

   ...

   public function attributeLabels()

   {

      return array(

         'name' => 'Name',

      );

   }

   ...

}