Zend Framework – Using a Modular Directory Layout

Considering that you already try to build an application with Zend Framework you already use the default module. If you want to expand your application to use more than one modules then you have to define the default module and  use a modular directory layout. A modular directory layout enforces consistency and produces a more manageable code tree.

How to Create the Default Module

The first step is to create the $APP_DIR/application/modules/ directory, and then create a set of subdirectories within that for the default module and its controllers, models and views. The zf command line tool does not create these directories, and so it is necessary to perform this task manually. In your application’s directory under the htdocs directory, there is a directory that is named application where you have to create a directory named modules and in this directory, a directory named default.

shell> cd /usr/local/apache/htdocs/square/application

shell> mkdir modules

shell> mkdir modules/default

 

Next, move the existing models, controllers, and views from $APP_DIR/application/* to

$APP_DIR/application/modules/default/*:

shell> mv controllers modules/default/

shell> mv views modules/default/

shell> mv models modules/default/

Updating the Application Configuration File

The next step is to update the global application configuration file, located at $APP_DIR/

application/configs/application.ini, with the location of the modules directory. This tells the

Zend Framework’s routing subsystem how to resolve module-specific entities.

To perform this update, open the application configuration file in a text editor and add the

following lines to the [production] section:

resources.frontController.moduleDirectory = APPLICATION_PATH “/modules”

resources.modules = “”

 

*info Regardless of whether or not you organize your application into modules, remember

that you can always redirect URL requests to specific modules, controllers, and actions

through the use of custom routes.