1
votes

I'm using CakePHP 2.2.3 and I need to build an admin/dashboard area for my site.

I have many models and controllers related to this models and in the dashboard I need to have the ability to CRUD all posts/users/news etc.

Obviously I need to build a Dashboard controller with some index action which will be show dashboard "home" page.

My question is: where to put all other actions – for posts/users/other things adding/editing ? Should I put all this actions in this new dashboard controller or it's better to put this actions to related controllers(Posts/Users..)?

2

2 Answers

4
votes

Keep your specific actions in each of their own controllers. A DashbaordsController is fine for whatever pages need to display a lot of different model information, but CRUD actions should be kept in their own Controller.

If you want/need a single page to be able to actually do the CRUD actions ON that page, you can use ajax and STILL call the actions of that specific Controller.

Bottom line, if you try to put all your CRUD into a single Controller, it's just going to get messy, and will be very confusing for future programmers (which includes yourself 6 mo from now).

It's so easy to include data from other Models $this->loadModel('MyModel');, that doing CRUD actions in their own respective Controller is not much of a hindrance. Again - the DashboardsController is still fine for those few pages that really are like dashboards, and have no alliance toward a specific model. But not for each model's CRUD.

0
votes

Generally the ideal way is to do skinny controllers and keep logic as far down the stack as possible that is near to the models. Ideally you'd want to introduce libraries for code reuse and testing. Robert Martin aka Uncle Bob says that the web delivery and databases should be as much of a plugin as possible. This lets you unit test much better. As far as your particular case i'd want to keep it close to REST as i can so separate controllers ideally delegating to some lower level stuff.