Best Practice When to Create Controllers?


#1

According to what I’ve read you should have thin controllers and fat models, ok so essentially just have them display the view? But what I can’t understand is how do you split up your controllers? If creating a CMS You have the Main website, back end, and the user’s front end. The question is how do you decide how to split that up? The Main Site isn’t going to be very big. So should that be one controller, while the user front end will just need to grab the database and/or files/images and display them on page, that piece is under one controller, but then the back end should then be split up by feature? If you have users upload items would items be a controller then? I’m extremely confused by this.


#2

First explain please what exactly do you mean by terms main website, frontend and backend. Are they separate pages?


#3

@mesiarm
Hopefully the below will help make it clearer as to what I mean. I’m going to end up with essentially 3 sites. Or should I completely make 3 separate cakePHP applications? I guess I never thought of that… It just seems silly to have one controller for the “Main Site” and call that application completed.

  1. The main site is where a user will come in sign up, pay for services, login etc.
  2. The Backend is where that user will be able to manage the content they want displayed on the front end.
  3. The Frontend is where the user’s customers will view the site.

#4

Okay, you should study cakephp tutorial to understand how it works more precisely, but in short. First you should design and create database tables. In your case there will be tables like: users, payments, pages. Then you will create models and controllers for all tables. You can find more information in tutorial here: https://book.cakephp.org/2.0/en/cakephp-overview/understanding-model-view-controller.html and then continuing with controllers, views, models chapters.