Zend Route: if link starts with /something then ignore other rules

508 views Asked by At

I have two modules that should over ride other urls, basically

/management/category/edit/id/1 (Edit Category Page)

/management/category/index (Index Page Of Category in Management Module)

/management/category (Index Page Of Category in Management Module)

/women-like-men/category (URL Routed from /default/category/view/id/women-like-men)

The rules for the above are:

    $router->addRoute('view-category',      new Zend_Controller_Router_Route(':id/category/:page',  array('module' => 'default', 'controller' => 'category', 'action' => 'view', 'page' => null)));
    $router->addRoute('management/category',    new Zend_Controller_Router_Route('management/category/',    array('module' => 'management', 'controller' => 'category', 'action' => 'index')));

There are alot of similar pages like this that "conflict" (Gallery, Movie, User) etc.

What I would really like is a rule that says /management/* route to module management/controller/action and ignore the rules below, anything with /management over rides. The likely hood of a user/gallery/movie/category being called management is low anyway.

Is it possible?

Edit, I have made this:

    $router->addRoute('administration',         new Zend_Controller_Router_Route_Regex('management/?(.*)/?(.*)', array('module' => 'management'), array(1 => 'controller', 2 => 'action')));

/management/category works fine, however anything after results in a 404

1

There are 1 answers

0
Tim Fountain On BEST ANSWER

This should be straightforward. The order your routes are defined is important - they are checked in reverse order, so in order for your management rule to 'override' the others you want it to be defined last (i.e. after all your other routes). Something like this (which is basically what you have) should work:

$route = new Zend_Controller_Router_Route(
    'management/:controller/:action/*',
    array(
        'module' => 'management'
        'controller' => 'index',
        'action' => 'index'
    )
);
$router->addRoute('management', $route);

If any of your management URLs are still 404'ing after this then they're not matching that route, so it either needs adjusting or you need some other management routes to match the other cases.