Zend Framework在网址中不包含默认模块 [英] Zend Framework not include the default module in url

查看:86
本文介绍了Zend Framework在网址中不包含默认模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的ZF1.12项目:

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

application.ini中的模块配置

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[] = ""

这些链接

$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'));

在/project.com/返回

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...

和/project.com/default/中的相同链接return

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

出问题了,当然,我应该总是得到相同的回报. 第二,也给我一个404错误.如果我将/project.com/default/index/one 放在地址中,则会显示类似的错误浏览器中的栏.

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.

为什么url()方法不返回包含默认"模块的URL?

推荐答案

我有类似的设置,并使用自定义路由:

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"

使用路由的一些详细信息:动作参数路由在Zend框架的routes.ini中不起作用.

Some good details for using routes: action parameters routing not working in Zend framework routes.ini.

但是基本上,在您的引导程序中,添加功能_initRoutes(来自上一个链接),并使用上述内容在/configs下创建一个route.ini文件

But basically, in your bootstrap add the function _initRoutes (from previous link), and create a routes.ini file under /configs with the above

-

此外,您可能还需要研究$front->setParam('useDefaultControllerAlways', true);(请参阅文档

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.

这篇关于Zend Framework在网址中不包含默认模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆