We were talking about routing on the #zftalk IRC channel. One of the users mentioned that rather than using routes, he was using the __call method in the IndexController.
I then asked him why is he doing that, as I knew routes would be more than a good choice for most kinds of URLs.
I found out that he was working with SEO and he was using a very interesting URL scheme: domain.com/productname-numbers-categoryname.html
This is actually quite interesting thing to think about. Not the SEO part, but how to make ZF understand these kind of URLs. The default routing in Zend Framework works very well for typical Zend’ish URLs like domain.com/hello/world/stuff/goes/here, but if you want to do some more specialized URLs, like the example here, you may need to do some thinking.
Because ZF is so flexible, I can think of four different ways to route complex URLs:
- Using __call
- Using a controller plugin
- Using Zend_Controller_Router_Route_Regex
- Customizing the Route class
These methods can be used for other things as SEO URLs as well, so let’s check out how to utilize these four and their pros and cons.