ZF-1808: Allow controllers in default module to be namespaced

Issue Type: Improvement Created: 2007-08-03T09:17:43.000+0000 Last Updated: 2008-03-21T16:25:17.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

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

Related issues: - ZF-2429



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:

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


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,


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.

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.