Saturday, April 3, 2010

Setting up controllers and models with multiple tables and dependencies

Hi,

I'm starting off with cakephp and am having some trouble with setting up the controllers and models for a DB design that I've come up with.

I've got a Products table and a Properties table which are independent of each other. I've got a link table product_properties which links up the products to the properties and also has a 'value' field which allows for a value to a particular property of a particular product. This allows me to add new properties or new products at any time without disturbing the existing ones.

To summarise:

products --------< product_properties (1-many)
properties ---------< product_properties (1-many)

A product has many properties, a property may be common to many products.

The book says we should have one controller for each model. In this case, I've got 3 models which would imply I should have 3 controllers. But in this case, wouldn't it make sense to just have one controller (called just products_controller.php) which works on all 3 models? Or have a main controller which controls all the three controllers?

If not, what is the right way to set up controllers for these models?

Apologies if this is a very basic question, but I'm having some trouble getting my head around cakephp and MVC style architecture. Any help will be greatly appreciated.

Thanks,
Plasty.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: