Insert multiple values

I have three tables

  1. products,

  2. sites and

  3. product_sites with columns product_id and site_id.

1st question. How should I configure the input form of the products to have a listbox on the form which I choose 1 or 2 sites for the new product?

2nd question. How should I modify the controller function actionCreate,

I want the inserted records in table product_sites will be 2, i.e. the first row product_id 1700 site_id 1 and the second row product_id 1700 site_id 2. yii 1.1.15. The model relation of products and sites are many to many.

Hi,

I think you can use the widget emultiselect in the view, to associate the sites to the product. I use together with the methods getRelatedData() from GxController and saveWithRelated() from GxActiveRecord (giix extension).

plenty of resources available here

http://www.yiiframework.com/doc/guide/1.1/en/form.table

http://www.yiiframework.com/wiki/559/tabular-input-validating-and-saving-related-models/

http://www.yiiframework.com/wiki/141/javascript-tabular-input