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

Issue Type: New Feature Created: 2008-03-18T09:26:47.000+0000 Last Updated: 2008-09-02T10:39:05.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Jurrien Stutterheim (norm2782) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments:


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.

<pre class="highlight">
 * 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.


Posted by Wil Sinclair (wil) on 2008-03-25T20:41:12.000+0000

Please categorize/fix as needed.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T10:25:30.000+0000

Scheduling for next minor release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-08-04T14:27:33.000+0000

Added to trunk and merged to 1.6 release branch.

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:05.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.