user1592129
user1592129

Reputation: 493

How to organize my cake views

I am new to CakePHP and started an application with it. I am facing a problem how to better organize my view.

My application has Categories and Categories have related products. in head I want to display all available categories and as user click on a Category name all it's related product will be displayed under Categories list.

Should I define both Categories and Product show in a single view? or a view which extends these to view and where should I created these views? As these belong to 2 different models.

And how data will be feteched as I want to access product of only selected category not for all categories.

Upvotes: 1

Views: 86

Answers (1)

Marcel Hebing
Marcel Hebing

Reputation: 3182

As you are new to cakePHP I would recommend to "bake" the controllers, models and views for your Categories and Products. When you bake them, you will be able to define the one-to-many-relation between both (Product belongs_to Category and Category has_many Products).

The result will be, that the Category-views automatically contain a list of related Products.

(You have to bake Category first and Product after that...)

Upvotes: 1

Related Questions