3

I need to create some module specific routes, but without explicitly mentioning module name in route. Right now I have separate config file for each module (MODULE/configs/module.ini) and in the module bootstrap I push those routes into Zend Framework. The INI file holds routes information but it mention the module name in the route. e.g.

routes.contents.route = "Contents/(.*)"
routes.contents.defaults.module = Contents
routes.contents.defaults.controller = index
routes.contents.defaults.action = index
+other details regarding the route.

You can see that the module name ("Contents") is explicitly mentioned in the route. What I want is that in the routes I just mention the portion after the module name and it automatically prepend the module name before the route. So later if I rename the module to lets say CMS, I don't ve to change every route into "CMS/xxxx".

Bryan
  • 645
  • 1
  • 6
  • 18

1 Answers1

0

The 'route' you specify can be anything you want. If Zend Framework matches it, it will execute the route based on the defaults set below.

resources.router.routes.products.regex = "somethingawesome/(.*)"
resources.router.routes.products.defaults.module = "ModuleName"
resources.router.routes.products.defaults.controller = "awesome"
resources.router.routes.products.defaults.action = "cool"

The above 'route' uses the regex match for - mysite.com/somethingawesome/whatever and will route it to the module: ModuleName, controller AwesomeController.php and run the coolAction()

There are lots of other matches you can do within this regex, but the string 'somethingawesome' is entirely up to you. It's all about what you want to match in the URL and where you want to send it to.

Darryl E. Clarke
  • 7,537
  • 3
  • 26
  • 34
  • I am using it, but in most of the modules, the routes starts with module name. somethingawesome = module name. so I was looking for a way that I just enter the route after the slash after "somethingawesome" and the application automatically prepend the module name(somethingawesome). Lets say my module name is realestate, and i want to route realestate/(.*) to module=>realestate, controller=>index, action=>index and getting (.*) value using getParam. I only want to add /(.*) into the route config, so if later I rename the module into "commercial" I don't ve to change all the routes. – Bryan Nov 23 '10 at 16:18
  • If you want "/realestate" to go to a module called "somethingelse" then you just change it in the '.module' configuration line. The route regex set for "/realestate" wouldn't have to change at all. If you want "/realestate" to be "/" and go to "somethingelse" change both lines. I think you might also need to disable the default routes if you want "/realestate" to stop working when it is configured as just "/". – Darryl E. Clarke Nov 23 '10 at 16:35
  • Now that I think about it a route of "/(.*)" will intercept everything and all other modules/routes will not work. Just a heads up. – Darryl E. Clarke Nov 23 '10 at 16:41