I’m new to CakePHP. Please help me to write a function to retrieve posts under a particular category for my blog app built using CakePHP.
My table structure:
posts: id, post, body, created, category_id
category: id, group
Also I had defined:
Inside post model – var $belongsTo = 'Category';
Inside category model – var $hasMany = 'Post';
find()is the generic query method for Models in CakePHP.An example would be:
There are many ways to achieve what you want. I encourage you to read the docs or working through the CakePHP Blog Tutorial.