2

I have the following structure of my system:

application/
   configs/
     application.ini
     router.php
   layouts/
   modules/
      default/
        controllers/
        forms/
        models/
        views/
        Bootstrap.php
      test/
        controllers/
        forms/
        models/
        views/
        Bootstrap.php
    Bootstrap.php

routes.php file:

$useDefaultRoutes = false;

$routes['index'] = new Zend_Controller_Router_Route(
                       '', 
                       array('controller' => 'index',
                       'action' => 'index', 
                       'module' => 'default'));

Main Bootstrap.php file

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    public static function setRoutes(){

        $frontController = Zend_Controller_Front::getInstance(); 
        $router = $frontController->getRouter();

        $routes = array();


        if(file_exists('../application/configs/routes.php'))
        {

            require_once "configs/routes.php";

            foreach($routes as $routeName => $routeValue){
                $router->addRoute($routeName, $routeValue);
            }

            if($useDefaultRoutes == false)
            {
                $router->removeDefaultRoutes();
            }

        }

    }

    protected function _initFrontModules() {
        $this->bootstrap('frontController');
        $front = $this->getResource('frontController');     
        $this->setRoutes();
    }

}

Problem

When I type in browser http://address, then default module launches IndexController and everything seems to be ok. But if I type http://address/test, then I get error - page not found. If I remove routes.php file, then it works. So what is the problem with my routing ?

Your help would be appreciated.

4
  • Is that your complete routes list? Commented May 17, 2011 at 9:55
  • Remove $useDefaultRoutes = false; Commented May 17, 2011 at 10:35
  • @ShaunHare Every module has its Bootstrap file. For example test module has its own: class Test_Bootstrap extends Zend_Application_Module_Bootstrap { } Commented May 17, 2011 at 11:13
  • @Ashley Nothing happens after removing. Commented May 17, 2011 at 11:14

1 Answer 1

2

Try this new way of routing...

Include this in your bootstrap.php

protected function _initAutoloadModules()
{
    $autoloader = new Zend_Application_Module_Autoloader(
        array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH . '/modules/default'
        ), 
        array(
            'namespace' => 'Admin',
            'basePath'  => APPLICATION_PATH . '/modules/test'
        )            
      );
    return $autoloader;
}

This is your application.ini

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
appnamespace = "Default"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.defaultModule = "default"
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "layout"
resources.modules = ""
resources.view[] =
resources.session.remember_me_seconds = 864000
resources.session.use_only_cookies = on
includePaths.models = APPLICATION_PATH "/models/"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

and in module/default/bootstrap.php add below given variable

protected $_moduleName="default";

and in module/test/bootstrap.php add below given variable

protected $_moduleName="test";
Sign up to request clarification or add additional context in comments.

4 Comments

This one works ok, but do I have to add every module to autoloader ?
yes u have to add there only.. with this approach you can even set the master layout in layout folder..
Is it possible to make it totally dynamic ? Without adding to Autoloader ?
Ive tried doing $frontController->addModuleDirectory(APPLICATION_DIR . '/modules/modulename'); With no success. Adding each module separately as above was only thing worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.