Reputation: 2095
I have the following structure of my zend framework:
application/
configs/
application.ini
routes.php
layouts/
scripts/
includes/
layout.phtml
modules/
somemodule1/
controllers/
IndexController.php
ErrorController.php
models/
views/
helpers/
scripts/
error/
error.phtml
index/
index.phtml
forms/
Bootstrap.php
somemodule2/
controllers/
IndexController.php
ErrorController.php
models/
views/
helpers/
scripts/
error/
error.phtml
index/
index.phtml
forms/
Bootstrap.php
Bootstrap.php
library/
Zend/
CustomClasses/
public/
css/
images/
js/
uploads/
.htaccess
index.php
Im trying to make it modular. For example I want to reach every module like this: domain.com/modulename/controller/action/someotherparams. If I add new module, so it should load automatically without any changes to the routing class. What I already done is:
**routes.php**
protected function _initAutoloadModules()
{
$autoloader = new Zend_Application_Module_Autoloader(
array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/somemodule1'
),
array(
'namespace' => 'Admin',
'basePath' => APPLICATION_PATH . '/modules/somemodule2'
)
);
return $autoloader;
}
**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/"
But actually its not working the way I want. Because I can't make the modules load automaticaly without changing the routes.php file (after new module was added to the system). So can anybody help me out?
Upvotes: 0
Views: 229
Reputation: 691
The behavior you want to achive is default behavior from Zend Framework. Try it this way:
$moduleLoader = new Zend_Application_Module_Autoloader
(
array
(
'namespace' => '',
'basePath' => APPLICATION_PATH
)
);
Do not forget to to use module prefix in controller name: Somemodule1_IndexController.
Upvotes: 1