问题
I have a ZF1.12 project with this structure:
|Project
|-Application
|-configs
|-application.ini
|-modules
|-default
|-configs
|-controllers
|-models
|-views
|-Bootstrap.php
|-api
|-configs
|-controllers
|-models
|-views
|-Bootstrap.php
|-Bootstrap.php
|-Library
|-Public
module configuration in application.ini
resources.modulesetup[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "default"
resources.modules[] = ""
these links
$this->url(array('module'=>'default', 'controller'=>'index', 'action'=>'index'));
$this->url(array('module'=>'default', 'controller'=>'index', 'action'=>'one'));
$this->url(array('module'=>'admin', 'controller'=>'index', 'action'=>'index'));
$this->url(array('module'=>'admin', 'controller'=>'index', 'action'=>'two'));
at /project.com/ return
/project.com/ ---> works
/project.com/ ---> no module, no controller and no action...
/project.com/admin/ ---> works
/project.com/admin/ ---> no controller and no action...
and the same links at /project.com/default/ return
/project.com/ ---> works
/project.com/index/one ---> doesn't work and return 404 error
/project.com/admin/index/index ---> works
/project.com/admin/index/two ---> works
Something is wrong, of course, I should have always the same return. The second one, also, gives me a 404 error.. I aspected something like /project.com/default/index/one that works if I put it in the address bar in browser.
Why the url() method does not return the url with the "default" module included?
回答1:
I have a similar setup, and use a custom route:
[routes]
routes.mycustomroute.type = "Zend_Controller_Router_Route_Regex"
routes.mycustomroute.route = "([a-zA-Z]+)/([a-zA-Z]+)"
routes.mycustomroute.defaults.module = "default"
routes.mycustomroute.map.1 = controller
routes.mycustomroute.map.2 = action
routes.mycustomroute.reverse = "%s/%s/%s"
Some good details for using routes: action parameters routing not working in Zend framework routes.ini.
But basically, in your bootstrap add the function _initRoutes
(from previous link), and create a routes.ini file under /configs
with the above
--
Also, you may also want to look into $front->setParam('useDefaultControllerAlways', true);
(see docs http://framework.zend.com/manual/1.12/en/zend.controller.router.html). But I'm unsure of what it does.
来源:https://stackoverflow.com/questions/16068776/zend-framework-not-include-the-default-module-in-url