views:

328

answers:

2

I'm trying to use modules in the ZF 1.8 project but can't get working routing to modules' actions.

Here is an example, I create route "/test" that points to module 'test', controller 'ttt' and action 'index':

$router->addRoute(
    $name, 
    new Zend_Controller_Router_Route('test',
        array('controller' => 'ttt', 
           'module' => 'test',
              'action' => 'index'))
);

I initilaize modules directory (create diretory "ttt", required controller and view classes) and specify it during bootstrap:

$front->addModuleDirectory(dirname(__FILE__) . '/modules');

But when I open URL like example.com/test I'm getting error like "Message: Invalid controller specified (ttt)".

What's wrong with my example?

Fixed. Added the following line into the application.ini:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
A: 

Have you copied another Controller class file, renamed it and forgotten to change the class declaration to TttController inside the file? That would get you that error message, if the controller does actually exist. Make sure it looks like this:

class TttController extends Zend_Controller_Action
{
...

Of course, I could be way off.

karim79
No, I've created controller using zf tool. It's ok.
Sergei Stolyarov
Zend_Tool is pretty buggy as far as I know, so better double check that it generated the right files with the right names.
Ionuț G. Stan
Yep, I've already reported two bugs and a few minutes ago found another one. So I always check generated code. It just doesn't work so I think that's a 1.8 version bug.
Sergei Stolyarov
I think there are problems with Zend_Tool, but regardless, it won't find the class unless it's named as per my answer
David Caunt
+3  A: 

For controllers not in the default module, you must prefix the controller class name with the module name and an underscore.

i.e.

class Test_TttController extends Zend_Controller_Action
{

}
David Caunt
You're right, class should be named in that way and also application.ini should be populated with resources.frontController.moduleDirectory parameter. For some reasons setting this parameter from Bootstrap.php doesn't work. And also zf.sh incorrectly creates code for files in the module.
Sergei Stolyarov
Yeah, they probably shouldn't have included Zend_Tool with the 1.8 release, as it's clearly not ready. Have faith though, it'll be sorted out soon :)
David Caunt