Need Help with a form that (should) saves information for 2models

FIRST: title is wrong :P when i started the post i was trying the cookbook of 2models in 1 form, now i realize that if im gonna ask i should ask bout my REAL requirement, not the work around i was trying to implement.

Hi , i’m new with Yii and im having some problems creating a simple web application. After a day trying to figure it out, i need help with the following issue :expressionless:

1-I have a HAS_MANY relationship where a Product has many pictures (and ,ofc each picture belongs to a product)

(relevant) TABLES


Product: id, code, description, category_id

Product_Image: id, product_id, image_name


What i need:

save product (OK) -> save the picture ->save the picture data in the product_image table.

I’m having some problems saving the picture data in the table, i know how to upload the picture but again, i can’t upload the picture in the products controller and i can’t call the product_images controller while im using the products_controller.

What should i do ?

LD;TR

The ideal solution is to have the add product form and then call the product_image creation form with the product_id already loaded in the model so i can save it. Any ideas about how to do this ?

I appreciate any help you can give me, a link to a similar case in the forums or anything that can help me with this problem.

PS: Im really , really bad writing (or talking, to be honest) about programming issues or solutions… so please let me know if i have to clarify something or give you more information. THANKS

Why? Is there any application-specific reason not to do it?

There’s no absolute need for a dedicated controller for each model class. Since Product_Image always belongs to a Product you can manage Product_Images in ProductController and remove ProductImageController entirely.

I usually create one controller per Aggregate Root in my applications.

Thanks for the information phtamas.

NOW, About my problem, the project is working, not the exact way i want it to work but it’s working fine.

I use both product_images_controllers and product_controller. I can add 1 picture in the product creation form and then i can add more in the image uploading form using the product_images controller.

I’m trying to figure out multi-upload now so i can make this thing look cool and be a bit more user-friendly.

Closing the thread so nobody wastes time in this.

(its incredible how i waited more than 1 day to ask and now its almost solved _:P)