Zend Framework Regex Router Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Zend Framework Regex Router Question

Post by shiznatix »

Hi everyone,

I am trying to setup a router configuration file to route some pages and while I have a way that it will work I am trying to come up with an easier way. Basically, I have pages with URLs like this:
coolba-en-jg4jf9
coolba-en-jg4jf9/thanks
coolba-de-hg7377
coolba-de-hg7377/thanks
and I want to route these to the controller Coolba and the first one to the "index" action and the second one to the "thanks" action. I am using Zend_Controller_Router_Route_Regex to get these all sent to the proper controller but I can't figure out how to use the router to go to the correct action without having to create a second router for each action. It is these multiple routers - one for each action - which will start to get really huge and unmaintainable. If I could just do some code on 1 line to route to the proper actions then all would be great.

Here is what I am using now which, although it works no problem, seams to be a bit dirty:
coolbaIndex.type = "Zend_Controller_Router_Route_Regex"
coolbaIndex.route = "othermodule/coolba-(\w{2}\-[\w\d\W]{6})"
coolbaIndex.defaults.module = "othermodule"
coolbaIndex.defaults.controller = "Coolba"
coolbaIndex.defaults.action = "index"

coolbaTest.type = "Zend_Controller_Router_Route_Regex"
coolbaTest.route = "othermodule/coolba-(\w{2}\-[\w\d\W]{6})/thanks"
coolbaTest.defaults.module = "othermodule"
coolbaTest.defaults.controller = "Coolba"
coolbaTest.defaults.action = "thanks"
Can anyone help me get that into 1 router instead of 2?
Post Reply