-- Jack Sleight <[EMAIL PROTECTED]> wrote
(on Friday, 03 August 2007, 02:40 PM +0100):
> In the application I'm creating I want to be able to dynamically specify 
> which module the dispatcher should use as the default module. I've 
> worked out how to do this, by calling:
> 
> $frontController->getDispatcher()->setDefaultModule($default)
> 
> However, ZF's default behaviour is to expect the controllers (and I 
> assume to models?) that belong to the default module not to be name 
> spaced (with ModuleName_), but because the default module will change 
> from request to request, I want to name space all modules, including 
> those being used as defaults. How can I tell the dispatcher that the 
> default should also be name spaced?

You'll need to subclass the dispatcher, and override the
loadClass($className) method. The following should do it:

    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 "' . $class
        }

        $className = $this->formatModuleName($this->_curModule) . '_' . 
$className;

        if (!class_exists($className)) {
            require_once 'Zend/Controller/Dispatcher/Exception.php';
            throw new Zend_Controller_Dispatcher_Exception('Invalid controller 
class ("' . $classNam
        }

        return $className;
    }

It's a minor change from the current dispatcher, and I'm thinking it
might be good to have a flag for 'alwaysUseModulePrefix' that would make
this behaviour possible. What do others think?

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to