phpmodulezend-framework

Can't find module controller


I'm trying to set up a module for the first time and I'm running into this error:

Exception information:

Message: Invalid controller specified (index)
Stack trace:

#0 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Controlle\Front.php(954):   Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),  Object(Zend_Controller_Response_Http))
#1 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 C:\Program Files (x86)\Zend\Apache2\htdocs\dev.paygiant.com\public\index.php(30):  Zend_Application->run()
#4 {main}  

Request Parameters:
array (
  'module' => 'admin',
  'controller' => 'index',
  'action' => 'index',
)  

My application directory:

configs/
controllers/
modules/
    Admin/
        controllers/
            IndexController.php
        models/
        views/

The admin index controller:

<?php

class IndexController extends Zend_Controller_Action {

public function init()
{
   // 
}

public function indexAction()
{
    // action body
}
}

My application.ini file contains:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = 

in my bootstrap file:

public function _initModuleLoaders()
{
    $this->bootstrap('Frontcontroller');

    $fc = $this->getResource('Frontcontroller');
    $modules = $fc->getControllerDirectory();

    foreach ($modules AS $module => $dir) {
        $moduleName = strtolower($module);
        $moduleName = str_replace(array('-', '.'), ' ', $moduleName);
        $moduleName = ucwords($moduleName);
        $moduleName = str_replace(' ', '', $moduleName);

        $loader = new Zend_Application_Module_Autoloader(array(
            'namespace' => $moduleName,
            'basePath' => realpath($dir . "/../"),
        ));
    }
}

What am I doing wrong?


Solution

  • You do not need anything at all extra in your main Bootstrap.php for modules.

    You do, however, need a Bootstrap.php in each module's directory. In your case this would be the modules/Admin directory.

    This new Bootstrap.php should contain the following:

    <?php
    class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
    {
    }
    

    I also think that module directories should start with a lowercase letter and yours starts with an uppercase.