Reputation: 2095
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.
Upvotes: 2
Views: 4239
Reputation: 811
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";
Upvotes: 2