I am working with Urls in the following format: "controller/action" where the slash is required.
I need to create a PCRE regex to match the controller and action names unless the controller name has the value of "home." For example:
- "member/update" should produce "member", "update"
- "admin/index" should produce "admin", "index"
- "home/index" should produce
<nomatch>
I've been playing around with look ahead, behind, and around and I have parts of it working but no totally correct solution. Any help appreciated.
** EDIT
Here's a little more background. I want to set up Zend routing so that
- an url with just one part '/foo' dispatches to HomeController, i.e. '/home/foo'
- any url with two parts '/controller/action' dispatches to that controller: e.g., '/member/update' dispatches to MemberController, '/member/update'; '/home/index' dispatches to HomeController, etc.
Right now I have routes set up as:
$router->addRoute('homeRoute',
new Zend_Controller_Router_Route(
':action',
array('controller' => 'home', 'action' => 'index')
)
);
$router->addRoute('memberRoute',
new Zend_Controller_Router_Route(
'member/:action',
array('controller' => 'member', 'action' => 'index')
)
);
// and so on, a route for each non-Home controller: adminRoute, etc
This is working the way I want but it's ugly and a maintenance problem. I'm want to replace all of the routes 'memberRoute', 'adminRoute', etc, with a single Regex route:
$router->addRoute('siteRoute',
new Zend_Controller_Router_Route_Regex(
'????/:action',
array('action' => 'index'),
array(?? => 'controller')
)
);
I have been running my regex experiments with a little php script like:
<?php
preg_match('/????/', 'home/index', $output);
echo '0=>'.$output[0].';';
echo '1=>'.$output[1].';';
?>