2
votes

so I'm setting up a router

  protected function _initRoutes(){
      $front = Zend_Controller_Front::getInstance();
      $router = $front->getRouter();
      $routerInfo =  array('action' => 'theaction',
                           'controller' => 'thecontroller',);
       $route = new Zend_Controller_Router_Route(
                         'some/path',
                         $routerInfo
       );
       $router->addRoute('some/path', $route);

      return $router;
  }

so controller 'some' and action 'path' doesn't really exist. instead, when the user goes to /some/path, it should redirect to 'theaction/thecontroller' instead....

my question is...how do I set it so that I can accept an abitrary number of parameters after the /some/path...for instance, I want /some/path/other/param to also redirect to the same page...so as long as the first segment of the path is /some/path, regardless of what follows I want them all to redirect to the same controller and action

I know that you can do /some/path/*/*....but that'll only work if there's only 2 other path items after /some/path.....I want this to work for an arbitrary number of parameters....so /some/path/param1/value1/param2/value2/param3/value3 should also still work and it'll be as if the user typed thecontroller/theaction/param1/value1/param2/value2/param3/valu3...

1

1 Answers

1
votes

You simply use a single asterisk, eg

$route = new Zend_Controller_Router_Route(
    'some/path/*',
    array(
        'action'     => 'theaction',
        'controller' => 'thecontroller',
        'module'     => 'default'
    )
);

// can't say for sure but a slash in the route name is probably a bad idea
// try a hyphen instead
$router->addRoute('some-path', $route);

See the 3rd example here - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard

FYI, don't get the FrontController resource like that in your Bootstrap methods. Use this instead...

$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');