ZF-2910: Get a module directory from the front controller
Description
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.
Comments
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.