views:

553

answers:

2

Ok, I'm frustrated beyond words!

I have a ZF 1.9 application. The following is in my bootstrap.php:

$front = Zend_Controller_Front::getInstance();
$front->addModuleDirectory(dirname(__FILE__).'/modules');

I've put some trace code into the ZF library files, and I can see the call to addModuleDirectory and the subsequent internal call to addControllerDirectory - it's got the right values for the module name and the path. If I dump the internal _controllerDirectory variable (this is all in Library/Controller/Dispatcher/Standard.php, by the way), I can see my module directory.

The next thing my trace shows is that the default controller directory is added for the default controller - perfect.

However, on the next call to dispatch(), I'm again dumping the _controllerDirectory variable and it's only got the default module's controller directory. WTF? I have the trace going to a file... here it is (commented by me):

    -- first call, triggered by addModuleDirectory():
    Adding 13:09:08
    Module itemquestion
    Path /Users/don/Documents/Aptana Studio Workspace/cahoots2/application/modules/itemquestion/controllers

    -- You can see my dir is in here...
    _controllerDirectory contains: 13:09:08
    /Users/don/Documents/Aptana Studio Workspace/cahoots2/application/modules/itemquestion/controllers

    -- second call, triggered internally by ZF:
    Adding 13:09:08
    Module default
    Path /Users/don/Documents/Aptana Studio Workspace/cahoots2/application/controllers

    -- Where's my directory????
    _controllerDirectory contains: 13:09:08
    /Users/don/Documents/Aptana Studio Workspace/cahoots2/application/controllers

What in the world am I doing wrong? Why can't I get my module's directory to stay persistent?

EDIT: Some additional detail. I added a second module to the /modules folder. Now, I can see the first module being added and showing up in the _controllerDirectory variable. Then, I can see the second added, and see BOTH of them in the variable. Then I see the default module added and after that call, it's the only thing in _controllerDirectory.

+3  A: 

Okay, it seems the solution is to add this to the application.ini:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

Which is kinda unintuitive and at the very least not even remotely documented in the ZF reference manual. Oy. But this seems to have solved the problem.

Don Jones
I've been strugling with the module directory structure and propper setup aswell. The documentation af this subject is pretty poor ATM...
Nicky De Maeyer
A: 

Well I think it depends on what part you put it on the bootstrap, because, if you put it before the Application Resource Controller then it may overwrite. To make sure the front controller is bootstrapped you can use something like this:

protected function _initFrontModules() {
      $this->bootstrap('frontController');
      $front = $this->getResource('frontController');
      $front->addModuleDirectory('path/to/modules');
}

If you omit the bootstrap line it may execute first your method and then overwrite it with the one from the plugin.

Chris
Where is this code supposed to go? There is no context!
KOGI
In the Bootstrap File ;-)
Chris