ZF-2910: Get a module directory from the front controller


Getting the module directory can be used for access to the :module/models directory, or custom directories inside the module directory. E.g. :module/forms , :module/config (for module specific configs) This could be used in the proposed ModelLoader for example.

Of course it's easy to do dirname($controllerDirectory), but it would be more convenient to have the module directory available from a method inside the frontcontroller.

 * Get the module directory.
 * If no module is specified it will return the module directory for the
 * active module.
 * @throws Zend_Controller_Exception
 * @param string $module
 * @return string
public function getModuleDirectory($module = null)
    if (null === $module) {
        $module = $this->getRequest()->getModuleName();

    $controllerDir = $this->getControllerDirectory($module);

    if ((null === $controllerDir) || is_array($controllerDir)) {
        throw new Zend_Controller_Exception('Cannot locate the module directory');

    return dirname($controllerDir);

It returns the module directory for the current module, unless $module is specified. In that case it would return the module directory for the specified $module.


Please categorize/fix as needed.

Scheduling for next minor release.

Added to trunk and merged to 1.6 release branch.

Updating for the 1.6.0 release.