Zend Framework not include the default module in url

寵の児 提交于 2019-12-24 00:48:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!