ZF-1808: Allow controllers in default module to be namespaced
Description
Currently, Zend_Controller_Dispatcher_Standard does not allow controllers in the default module to be namespaced. This can cause an issue if setting the default module to a name other than 'default' in order to have an existing module be the default. A simple change to loadClass() would fix this. The new method would look like this:
public function loadClass($className)
{
$dispatchDir = $this->getDispatchDirectory();
$loadFile = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);
$dir = dirname($loadFile);
$file = basename($loadFile);
try {
Zend_Loader::loadFile($file, $dir, true);
} catch (Zend_Exception $e) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $file . '" in directory "' . $dir . '"');
}
$final = $this->formatModuleName($this->_curModule) . '_' . $className;
if (!class_exists($final)) {
if ((($this->_curModule == $this->_defaultModule)
&& !class_exists($className))
|| ($this->_curModule != $this->_defaultModule))
{
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid controller class ("' . $className . '")');
}
$final = $className;
}
return $final;
}
Comments
Posted by Patrick Nijs (patricknijs) on 2007-10-22T11:38:43.000+0000
Yes! This would be great. Especially as a developer it's convenient to have one framework available where you can plugin the several modules.
Posted by Patrick Nijs (patricknijs) on 2007-10-22T13:03:25.000+0000
You should change one line btw, just for esthetics:
$final = $this->formatModuleName(ucfirst($this->curModule)) . '' . $className;
Notice the ucfirst()?
Kind regards,
Patrick
Posted by Matthew Weier O'Phinney (matthew) on 2007-11-16T12:46:15.000+0000
Tentatively scheduling for 1.1.0
Posted by Wil Sinclair (wil) on 2007-12-14T18:43:07.000+0000
What is the status of this issue? Will the fix be included in 1.5?
Posted by Matthew Weier O'Phinney (matthew) on 2008-02-20T11:07:00.000+0000
Resolved in trunk. Passing the front controller or dispatcher parameter 'prefixDefaultModule' will ensure the controllers in the default module are namespaced.