问题
CakePHP is fantastic, it really deserves the slogan "Rapid Development Framework". I have been able to quickly bake controllers, models and also templates. Things were good for a while until I hit a brick wall. The application I'm developing is way too massive for the simple directory structure offered by default.
Half way in my development process, I started to see myself leaving lots of business logic inside of Table classes. I've heard sayings that it's not a good idea to pollute the model class with behavioral code.
Since my application is large that it requires several modules almost mini applications by themselves I need to use CakePHP a little differently. I will explain the structure of my application that I would prefer.
Application Structure (Architecture)
Core
This folder will contain all the modules my application is made of. Alternatively it should be called "Modules" instead of "Core".
Modules
Each module folder will have a folder for Controllers, Models, Services and Templates.
Model
This will contain two sub folders as the ones already offered by CakePHP 3. It will contain the folders for Entities and Tables. I have heard the table acts as a repository so I have omitted the idea of having a repository folder.
Service
The service folder will contain services for the module, mainly business logic code that uses Table Entities for data persistence and retrieval. This is to help keep the business logic centered and keep the model classes & controller thin.
Controllers
Controllers will be the ones talking with the service classes. Using the services to both retrieve data, save data, do validation, work with business logic...etc. My goal is also to also make the work of the controller very light, by moving most of the logic stuff into services.
Template
This will contain the view files that the controllers will use to render data back to the web browser. I might have sub folders in there for views for sub sections of the module.
Notes & Questions
Please forgive me If I have not explained my self properly, we are dealing with a very complex application that has many tables, approximately 100. If anyone has better recommendations for organizing a large application in CakePHP 3 I would really appreciate it.
By developing my application in this way I understand CakePHP will not work out of the box, I might need to reconfigure it so It can uses my custom directory structure. How easy will it be to do that?
来源:https://stackoverflow.com/questions/31581668/modular-directory-structure-with-cakephp