The first step to making use of modules is to modify how you specify
the controller directory list in the front controller. In the basic
MVC series, you pass either an array or a string to
setControllerDirectory(), or a path to
addControllerDirectory(). When using modules, you need
to alter your calls to these methods slightly.
With setControllerDirectory(), you will need to pass an
associative array and specify key and value pairs of module
name and directory paths. The special key default will be
used for global controllers (those not needing a module namespace).
All entries should contain a string key pointing to a single path,
and the default key must be present. As an example:
<?php
$front->setControllerDirectory(array(
'default' => '/path/to/application/controllers',
'blog' => '/path/to/application/blog/controllers'
));
addControllerDirectory() will take an optional second
argument. When using modules, pass the module name as the second
argument; if not specified, the path will be added to the
default namespace. As an example:
<?php
$front->addControllerDirectory('/path/to/application/news/controllers',
'news');
Saving the best for last, the easiest way to specify module
directories is to do so en masse, with all modules under a common
directory and sharing the same structure. This can be done with
addModuleDirectory():
<?php
/**
* Assuming the following directory structure:
* application/
* modules/
* default/
* controllers/
* foo/
* controllers/
* bar/
* controllers/
*/
$front->addModuleDirectory('/path/to/application/modules');
The above example will define the default,
foo, and bar modules, each pointing to the
controllers/ subdirectory of their respective module.
You may customize the controller subdirectory to use within your
modules by using setModuleControllerDirectoryName():
<?php
/**
* Change the controllers subdirectory to be 'con'
* application/
* modules/
* default/
* con/
* foo/
* con/
* bar/
* con/
*/
$front->setModuleControllerDirectoryName('con');
$front->addModuleDirectory('/path/to/application/modules');
Note
You can indicate that no controller subdirectory be used for your
modules by passing an empty value to
setModuleControllerDirectoryName().




