views:

33

answers:

2

I would like to have categories, and rankings for my content and users respectively, and I am not sure how to go about implementing this using CakePHP conventions?

Do I need to create a model?

+2  A: 

That depends entirely on what these categories are supposed to do and not do. You could simply define a number of constants that you use for categorizing stuff. But, are categories...

  1. subject to change? Do you want to add more eventually?
  2. editable? May you want to change their names?
  3. nested?
  4. supposed to have more attributes than just their id? Names, descriptions?

If you answered Yes to any of the above, you'll want to store them as data in the database. This is independent of Cake, it's just sane data modeling. For Cake that means you'll need to create a model. The same goes for ratings.

So you'll have these tables:

  • users
    • hasMany ratings
  • categories
    • hasMany contents
  • contents
    • belongsTo categories
    • hasMany ratings
  • ratings
    • belongsTo users (polymorphic)
    • belongsTo contents (polymorphic)

You may want to separate user ratings and content ratings into two tables instead of using a combined polymorphic table (which just means that you have an extra column keeping track of whether a rating is for a user or for content).

deceze
sweet. Thanks Deceze, That was perfect.
Anthony
Also worth noting that you can really take advantage of Cake's caching in an instance like this, where you don't expect data to change much. Turn caching on and you'll barely notice a performance difference in your app.
Travis Leleu
A: 

i guess you are looking for something like this IF you dont want to use a model: http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/

one possible approach to use "enums" for things that maybe only have 1-5 states.

if you have more than 10 or you want to be able to dynamically modify them (label, active/inactive) you will need a separate table and model relation.

mark