简体   繁体   English

Zend Regex>路由模块问题

[英]Zend Regex > Route module problem

iam using zend framework to build a REST web service and i am using modules to separate my api versions, as i have mentioned here 我使用zend框架来构建REST Web服务,我正在使用模块来分离我的api版本,正如我在这里提到的那样

Ex: "applications/modules/v1/controllers", "applications/modules/v2/controllers" have different set of actions and functionality. 例如:“applications / modules / v1 / controllers”,“applications / modules / v2 / controllers”具有不同的操作和功能集。 I have mentioned my default module as "v1" in my application.ini 我在application.ini中提到了我的默认模块“v1”

I am using context switching along with Regex Routing as i have mentioned here in my accepted solution: 我使用的上下文正如我刚才所说随着正则表达式路由交换这里我接受的解决方案:

$router->addRoute(
            'route1',
            new Zend_Controller_Router_Route_Regex(
                                            'api/([^-]*)/([^-]*)\.([^-]*)', 
                                            array(
                                                'controller'   => 'index',
                                                'action'       => 'index'),
                                            array(
                                                1 => 'module',
                                                2 => 'controller',
                                                3 => 'format'
                                            )
));

This is my url: http://localhost/api/v1/tags.xml 这是我的网址: http://localhost/api/v1/tags.xml

"v1" indicates module. “v1”表示模块。 Now, coming to context switching, if the url has v1, it is going to v1 module's TagsController. 现在,进入上下文切换,如果url有v1,它将转到v1模块的TagsController。 But if the module in url is v2, i am getting an error such as: 但是如果url中的模块是v2,我会收到如下错误:

The requested URL /pt/public/index.php/api/v2/tags.xml was not found on this server. 在此服务器上找不到请求的URL /pt/public/index.php/api/v2/tags.xml。

I could not understand why its blowing up. 我无法理解为什么它会炸毁。 Is it because i have put the default module as v1? 是因为我把默认模块设为v1吗? I am not able to change the module based on the url. 我无法根据网址更改模块。

And this is my directory tree: 这是我的目录树:

  • application 应用
    • modules 模块
      • v1 V1
        • controllers 控制器
          • TagsController.php TagsController.php
      • v2 V2
        • controllers 控制器
          • TagsController.php TagsController.php
  • library 图书馆

My goodness... i have figured out the solution... the controller class name in the v2 module must be "V2_TagsController", not just "TagsController". 我的天啊......我已经找到了解决方案...... v2模块中的控制器类名必须是“V2_TagsController”,而不仅仅是“TagsController”。 Thank God, it is working now :) See the class names for controllers below: 感谢上帝,它现在正在工作:)请参阅下面的控制器的类名称:

- application
      - modules
         - v1
            - controllers
                  - TagsController.php (class TagsController)
         - v2
            - controllers
                  - TagsController.php (class V2_TagsController)
- library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM