Reputation: 1187
I need to know how can I merge these routers into one? I want to have just one router instead of these ones. I appreciate any answer.:)
$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);
Upvotes: 0
Views: 1665
Reputation: 75252
So instead of the four routes you have now, you want one route in which the last three parameters are optional? Try this regex:
'([a-z]{2})(?:/(\w+)(?:/(\w+)(?:/(\w+))?)?)?'
Upvotes: 2