views:

22

answers:

2

Hello. My problem is I want some parameter values, passed through URL, don't trigger the Zend routing but lead to defaul controller/action pair.

Right now I have following in my index.php:

    // *** routing info ***
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute('showpage', new Zend_Controller_Router_Route('/show/:title',
                                                               array('controller' => 'Show',
                                                                       'action' => 'page')));
// annoying exceptions :(
$router->addRoute('addshow', new Zend_Controller_Router_Route('/show/add',
                                                               array('controller' => 'Show',
                                                                       'action' => 'add')));
$router->addRoute('saveshow', new Zend_Controller_Router_Route('/show/save',
                                                               array('controller' => 'Show',
                                                                       'action' => 'save')));
$router->addRoute('addepisode', new Zend_Controller_Router_Route('/show/addEpisode',
                                                               array('controller' => 'Show',
                                                                       'action' => 'addEpisode')));
$router->addRoute('saveepisode', new Zend_Controller_Router_Route('/show/saveEpisode',
                                                               array('controller' => 'Show',
                                                                       'action' => 'saveEpisode')));

without last 4 routers, URL /show/add leads to show/page, carrying title == 'add'. Please, every help will be much appreciated.

A: 

First, use Zend_Controller_Router_Route_Static for the static routes.

Secondly, I'm pretty sure you don't need to include the leading forward slash, though I'm not sure if this is an issue.

As routes are matched in reverse order, yours should work (I think). For anything not matching "saveEpisode", "addEpisode", "save" or "add", it should fall through to the "showpage" route.

The only other thing I could think of would be to make the "showpage" route more specific, something like

'show/page/:title'
Phil Brown
A: 

You can use a regular expression to reject add, save, addEpisode and saveEpisode

$router->addRoute(
  'showpage', 
  new Zend_Controller_Router_Route(
    '/show/:title',
    array(
      'controller' => 'show',
      'action' => 'page'
    ),
    array(
      'title' => '(?:(?!add)(?!save)(?!addEpisode)(?!saveEpisode).)+'
    )
  )
)
Maxence