Following the intro cakephp tutorial to create a blog, I created a database to view, add/edit/delete businesses. Each business has a state or province associated with it, and I’m wondering how I would go about to generate a page that lists all the States, like /states and a page would be like /states/california and lists all the businesses in california.
Right now I currently just have one page that lists all businesses. Wondering how I would design the model/controller/view and routes to handle this. Can’t really find a source online that elaborates on this or I just don’t know how to look.
Since you’re new to cake,I think it’s not a good idea to start from HABTM relationship which is what you need in your question and also the most complicated one.So I assume your models relationship as a easier one :hasMany.E.g as follows:
Then make the action in your state controller as this:
Now I think you may handle the view file yourself,with a
$statevariable to retrieve the data$thestatewhich also contains a businesses list in it.Now in the /app/config/routes.php do the routing part:
After finish that you may get what you need with
/states/somestate.When you go through this,you may try to solve this with the best way —hasAndBelongsToMany.