Check a condition and also identify the pattern in url through Regex in Zend

戏子无情 提交于 2020-01-01 19:07:11

问题


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

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

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.

How can it be achieved ?


回答1:


I know absoluely nothing about Zend, but the regex:

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

matches:

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

on the input:

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

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

HTH



来源:https://stackoverflow.com/questions/5298353/check-a-condition-and-also-identify-the-pattern-in-url-through-regex-in-zend

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