开发者

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

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 ach开发者_C百科ieved ?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜