Innovative Computer Solutions,
Development & Technical Support

07975 997026 • enquiries[delete-me]@[delete-me]

User Tools

Site Tools


Zend-Framework Modular Structure Step 1 - MVC

This first stage directs where ZF looks for its Models, Views and Controllers within a Modular structure.

Telling Zend Framework where Modules are located

Using application.ini method, edit your application.ini file at \wamp\www\PROJECT NAME\application\configs\application.ini (which in my case was \wamp\www\square\application\configs\application.ini)

Add the following lines in the [production] section:

  resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
  resources.modules = ""

Moving the Default module

When using a Module based system with Zend Framework's default Routes, the module name needs to be included in the URL request in this format: /module/controller/action. If the request doesn't contain the Module name, it looks in the 'default' location (ie. /APPLICATION PATH/application/). The directive above tells ZF not to look in its usual default location but to look in the modules folder instead for a module called 'default'.

For this to work, we need to move all the 'default' folders over into our module folder:

Create the folder

Create a folder named /application/modules/default

Move the existing default folders into the new default module

move to
/application/controllers /application/modules/default/controllers
/application/models /application/modules/default/models
/application/views /application/modules/default/views

If this all works, you can use either http://square.localhost/ or http://square.localhost/default/index/index to access the default application.

Using a Custom Route

When defining custom routes within application.ini, just remember to tell it which Module it needs to go to as well as the usual Controller and Action.

eg. a custom route to the homepage

  ; define the HOMEPAGE route
  resources.router.routes.home.route = /home
  resources.router.routes.home.defaults.module = default
  resources.router.routes.home.defaults.controller = index 
  resources.router.routes.home.defaults.action = index
programming/php/zend-framework/modular-structure-step-1-mvc.txt · Last modified: 15/06/2013 16:30 (external edit)