1

I have some issues with Zend_Controller_Router_Route. I have the following url in standard module/controller/action notation:

http://www.mysite.com/rent/index/region/myregion/town/mytown/district/mydistrict/filter_params/filter_values

module: rent controller: index

params: region, town, district

filter_params are some more pagination params and drilldown stuff

I want to strip it down to: http://www.mysite.com/rent/myregion/mytown/mydistrict/filter_params/filter_values/

But these should also work

http://www.mysite.com/rent/myregion/mytown/filter_params/filter_values

http://www.mysite.com/rent/myregion/filter_params/filter_values

I tried this route

$myRoute = new Zend_Controller_Router_Route(
    'rent/:region/:town/:district/*',
     array(
         'controller' => 'rent',
         'action' => 'index'
     )
);
$router->addRoute('rent', $myRoute);

This one works: http://www.mysite.com/rent/myregion/mytown/mydistrict

these ones fail

http://www.mysite.com/rent/myregion/mytown

http://www.mysite.com/rent/myregion

Action 'myregion' does not exist and was not trappend in __call()

How can I declare the other routes and what will happen to all the other params, when i have a route like http://www.mysite.com/rent/myregion/mytown/filter_params/filter_values

Thank you for your help!

Jesse
  • 4,323
  • 3
  • 17
  • 16

1 Answers1

1

It is because you added route which matches rent/:region/:town/:district/ and the two other condtions does not match this rule. You need create routes for

rent/:region/ rent/:town/

etc. You could do it but there is problem how to know that param is either town or region but it can be checked by adding regions and towns to database and looking for them or by adding some additional param and using regex.

Robert
  • 19,800
  • 5
  • 55
  • 85
  • Thanks robert. This did the trick. I now have a cascade of routes starting with the longest possible route and ending with the shortest. In this way all routes will be matched. – Jesse Nov 05 '13 at 07:57