Issues

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

Yes! This would be great. Especially as a developer it's convenient to have one framework available where you can plugin the several modules.

You should change one line btw, just for esthetics:

$final = $this->formatModuleName(ucfirst($this->curModule)) . '' . $className;

Notice the ucfirst()?

Kind regards,

Patrick

Tentatively scheduling for 1.1.0

What is the status of this issue? Will the fix be included in 1.5?

Resolved in trunk. Passing the front controller or dispatcher parameter 'prefixDefaultModule' will ensure the controllers in the default module are namespaced.