I'm writing the bits and pieces for a (oh no, another) PHP framework, as a learning experience, and hopefully for future use on smaller projects.
I've done a fair bit of reading, namely the Reference Docs of existing frameworks. I see the word Module thrown around alot, and from my reading and previous experience, a 开发者_如何学编程Module is a concept applied to divide related code (Views, Controllers, Models, etc.)
I'm curious, how does SO see a Module in this context? (context being MVC web application architecture, or similar application development pattern)
I'm trying to determine how best to apply this, as (I believe) it fits my current predicament. For a music website a module would be seen as an Artist
, Producer
, etc., whereas the Controllers would be Profile
, Media
, etc. This leaves actions of course, such as View
, or Edit
.
This all seems good, because now I can do routing like so:
'Artist/Profile/View/{ALIAS}'
+- Module : Artist
+- Controller : Profile
+- Action : View
//this may be accessed via music.com/artist/{alias}
//defaulting the Controller and Action
..but I'm trying to figure out how the Module concept fits here, specifically, how I would organize or modify my Controllers to accommodate.
This is the sort of file system layout I'm thinking of;
+- Root
+- 'index.php'
+- 'api.php'
+- Modules
| +- Public
| | +- Controllers
| | +- Views
| |
| +- User
| | +- Controllers
| | +- Views
| |
| +- Artist
| | +- Controllers
| | +- Views
| |
| +- Producer
| | +- Controllers
| | +- Views
| |
| +- Venue
| | +- Controllers
| | +- Views
| |
| +- Administrator
| +- Controllers
| +- Views
|
+- Models
+- Config
+- ...
Modules (called Plugins in CakePHP) are pretty much mini apps in most frameworks. They have their own MVC structure inside them and are usually self contained, maybe only relying on the main apps models to keep the code reusable.
We use Zend where we work, and examples of modules would be the
- Admin module for administrators of the site to do changes to the system.
- Web module for the general front end of the site
- User module for the logged in users who have additional management tools to carry out their activities on the site
Basically all of them fall under the same site/system, but deal in mostly non overlapping ways.
In the simplest case, a module will be a folder in you app (preferably in a pre-determined location, like /modules
). You will then have a whole MVC stack inside each module, with shared libraries and the framework itself being on the top level.
精彩评论