0

I have two models 'Company' and 'Vehicle'

And two tables in database named same as 'company_master' and 'vehicle_master'

company_master
fields: id, 
        name, 
        vehicle type, 
        country

vehicle_master
fields: id (auto increment), 
        company_id (foreign key),
        model_name,
        website,
        comments

When I select a random company, from CGridView to update record, I will get a form to update, that's all fine.

But I need a blank form for vehicle_master to create a record, inside company's update form.

Form Example

Above form is example of my html page "update" of company, along with initially "blank" form of Vehicle Detail.

I want to insert a new record when I click Add button of Vehicle Detail form.

Thanks in advance. God Bless Merry Christmas :-)

Darshit Gajjar
  • 746
  • 4
  • 13
  • 26

1 Answers1

1

If i understood your question correctly then this is a multi-model-form task, there are plenty of good examples for that, including this one http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/ and this one here: multi model forms in yii

The only two slight differences in your case [from the second link code]are:

  1. You will need to put the controller code in the Update action for your Company controller instead of the create action according to your business logic.
  2. You will need to add additional button to add vehicle independently, by simply sending the new vehicle params to the create action of your Vehicle controller.
Community
  • 1
  • 1
Nimir
  • 5,727
  • 1
  • 26
  • 34