在zend框架中使用Regex路由器,如何合并这些路由器?

时间:2009-08-09 17:22:05

标签: regex zend-framework router routes

我需要知道如何将这些路由器合并为一个? 我想只有一个路由器而不是这些路由器。 我很感激任何答案。:)

        $route = new Zend_Controller_Router_Route_Regex(
        '([a-z]{2})/(\w+)/(\w+)/(\w+)',
        array('controller'=>'index',
            'action' => 'index',
            'module'=>'default',
            'lang'=>$lang
        ),
        array(
            1=>'lang',
            2=>'module',
            3=>'controller',
            4=>'action'
        )
    );
    $router->addRoute('default_lang_action', $route);

    $route = new Zend_Controller_Router_Route_Regex(
        '([a-z]{2})/(\w+)/(\w+)',
        array('controller'=>'index',
            'action' => 'index',
            'module'=>'login',
            'lang'=>$lang
        ),
        array(
            1=>'lang',
            2=>'module',
            3=>'controller'
           )
    );
    $router->addRoute('default_lang_con', $route);

    $route = new Zend_Controller_Router_Route_Regex(
        '([a-z]{2})/(\w+)',
        array('controller'=>'index',
            'action' => 'index',
            'module'=>'default',
            'lang'=>$lang
        ),
        array(
            1=>'lang',
            2=>'module'
        )
    );
    $router->addRoute('default_lang_mod', $route);

    $route = new Zend_Controller_Router_Route_Regex(
        '([a-z]{2})',
        array('controller'=>'index',
            'action' => 'index',
            'module'=>'default',
            'lang'=>$lang
        ),
        array(
            1=>'lang'
        )
    );
            $router->addRoute('default_lang', $route);

1 个答案:

答案 0 :(得分:2)

因此,您需要一条路线,其中最后三个参数是可选的,而不是您现在拥有的四条路线?试试这个正则表达式:

'([a-z]{2})(?:/(\w+)(?:/(\w+)(?:/(\w+))?)?)?'
相关问题