Zend 正则表达式路由模块问题 [英] Zend Regex > Route module problem

查看:42
本文介绍了Zend 正则表达式路由模块问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 zend 框架构建 REST web 服务,我使用模块来分隔我的 api 版本,正如我提到的 此处

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

例如:applications/modules/v1/controllers"、applications/modules/v2/controllers"具有不同的操作和功能集.我在 application.ini 中提到了我的默认模块为v1"

Ex: "applications/modules/v1/controllers", "applications/modules/v2/controllers" have different set of actions and functionality. I have mentioned my default module as "v1" in my application.ini

正如我提到的,我正在使用上下文切换和 Regex Routing 此处 在我接受的解决方案中:

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

这是我的网址:http://localhost/api/v1/tags.xml

v1"表示模块.现在,进入上下文切换,如果 url 有 v1,它将转到 v1 模块的 TagsController.但是如果 url 中的模块是 v2,我会收到一个错误,例如:

"v1" indicates module. Now, coming to context switching, if the url has v1, it is going to v1 module's TagsController. But if the module in url is v2, i am getting an error such as:

请求的网址/pt/public/index.php/api/v2/tags.xml在此服务器上未找到.

The requested URL /pt/public/index.php/api/v2/tags.xml was not found on this server.

我不明白为什么它会爆炸.是不是因为我将默认模块设置为 v1?我无法根据 url 更改模块.

I could not understand why its blowing up. Is it because i have put the default module as v1? I am not able to change the module based on the url.

这是我的目录树:

  • 申请
    • 模块
      • v1
        • 控制器
          • 标签控制器.php
          • 控制器
            • TagsController.php

            推荐答案

            我的天哪...我想出了解决方案... v2 模块中的控制器类名称必须是V2_TagsController",而不仅仅是TagsController".感谢上帝,它现在正在工作:)请参阅下面的控制器类名称:

            My goodness... i have figured out the solution... the controller class name in the v2 module must be "V2_TagsController", not just "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
            

            这篇关于Zend 正则表达式路由模块问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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