检查条件并通过 Zend 中的 Regex 识别 url 中的模式 [英] Check a condition and also identify the pattern in url through Regex in Zend

查看:23
本文介绍了检查条件并通过 Zend 中的 Regex 识别 url 中的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施 Zend Regex Routing,我必须对 url 执行多次检查.例如,如果这是我的网址:

i am implementing the Zend Regex Routing, and i have to perform multiple checks for the url. For example, if this is my url:

http://localhost/application/public/index.php/module/controller/action

这是我的引导文件中的正则表达式条件,当 url 不包含登录"时匹配:

and this is my regex condition in my bootstrap file, which matches when the url does not contain "login":

$router->addRoute('ui', new Zend_Controller_Router_Route_Regex(
    '^((?!login/).)*$',
    array(
        'module'     => 'mod1',
        'controller' => 'cont1',
        'action'     => 'action1'
    ),
    array( )
));

现在我还想识别模式:([^-]*)/([^-]*)/([^-]*) 来自 url 以了解模块,控制器和动作,以便我可以路由到它.

Now i also want to identify the pattern: ([^-]*)/([^-]*)/([^-]*) from the url for knowing the module, controller and action, so that i can route to it.

如何实现?

推荐答案

我对 Zend 一无所知,但是正则表达式:

I know absoluely nothing about Zend, but the regex:

^(?=(?:(?!login/).)*$).*?/([^-/]*)/([^-/]*)/([^-/]*)/?$

匹配:

entire match: "http://localhost/application/public/index.php/module/controller/action", from 0 to 70
- group(1) = "module"
- group(2) = "controller"
- group(3) = "action"

输入:

http://localhost/application/public/index.php/module/controller/action

(?=((?!login/).)*$) 部分确保字符串中没有 login/,而 ([^-/]*)/([^-/]*)/([^-/]*)/?$ 抓取最后三个 .../ 结束前输入 ($).

The part (?=((?!login/).)*$) makes sure there is no login/ in the string, and ([^-/]*)/([^-/]*)/([^-/]*)/?$ grabs the last three .../ before the end of the input ($).

HTH

这篇关于检查条件并通过 Zend 中的 Regex 识别 url 中的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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