Zend Framework: Modular Structure
After searching for a long time I still couldn’t find any tutorials on how to set up my directories and code to enable a nice tidy logical folder structure that contains each module of a larger application.
The standard (non-modular) structure is as follows.
web_root/
application/
controllers/
views/
scripts/
models/
library/
htdocs/
To use a modular structure is actually very simple.
Create a ‘modules’ directory under the ‘application’ directory.
You guessed it – place all your module directories here. In each module directory is a standard MVC structure that you would normally see below the ‘application’ dir.
For example say you had a public area and an admin area. This is how it might look.
web_root/
application/
modules/
admin/
controllers/
views/
scripts/
models/
guest/
controllers/
views/
scripts/
models/
library/
htdocs/
This can be extended for as many modules as you wish.
You now need to declare where the modules are located to your scripts. There are a few ways to achieve this, but by far the easiest is to add one line of code to the bootstrap file.
$front->addModuleDirectory('/web_root/application/modules');
Thats it, unless you are using Zend_Layout which I plan to cover in part two of this tutorial.
For more information look in the Zend Framework Manual.
Category: PHP, Zend Framework Comment »