Robert Basic's blog

Archives for November, 2009

Chaining routes in Zend Framework

by Robert Basic on November 27, 2009.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

On a forum, there was a question today, about adding language “support” to the routes using Zend Framework. The guy wanted routes like /en/foo/bar or /de/baz. I wrote there an example for that using Zend_Router_Routes_Chain, so just posting that example here, too :)

For what chains are for, is described in the manual, so I won’t be covering that :P

Basically, we’re prepending the language route to the other routes. This way, we have defined the route for the languages in one place only, plus, the other routes don’t have to worry about the language, too.

// this goes in the bootstrap class
public function _initRoutes()
    $this->_frontController = $this->getResource('FrontController');
    $router = $this->_frontController->getRouter();

    $langRoute = new Zend_Controller_Router_Route(
            'lang' => 'en'
    $contactRoute = new Zend_Controller_Router_Route_Static(
        array('controller'=>'index', 'action'=>'contact')
    $defaultRoute = new Zend_Controller_Router_Route(

    $contactRoute = $langRoute->chain($contactRoute);
    $defaultRoute = $langRoute->chain($defaultRoute);

    $router->addRoute('langRoute', $langRoute);
    $router->addRoute('defaultRoute', $defaultRoute);
    $router->addRoute('contactRoute', $contactRoute);

Assuming that we have an Index controller, with actions index and contact and a Foo controller with actions index and bar, paired with the routes from the above example, we could do requests like:

/ => /index/index/lang/en
/de => /index/index/lang/de
/sr/contact => /index/contact/lang/sr
/en/foo => /foo/index/lang/en
/fr/foo/bar => /foo/bar/lang/fr

Requesting a page like, e.g. /de/baz, would give us a 404 page, cause we don’t have a Baz controller.

HTH :)

Happy hacking!

Tags: example, framework, php, route, routing, zend.
Categories: Development, Programming.

Zend Framework bug hunt days

by Robert Basic on November 22, 2009.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

On the 19th and 20th of this month, the third Zend Framework Bug Hunt days were held. I joined the party for the first time and I say, it was a jolly good one!

It was announced on Zend DevZone after which Pádraic wrote a nice and detailed Guide To Zend Framework Bug Hunt Days (I think I read on IRC that there’ll be a Bug Hunt Day FAQ, too). I decided to try and give back to the community as much as I can. OK, it wasn’t much - submitted a patch for an issue and closed another which was lacking information - but hey! I think it was pretty good for a noob bug hunter like me :P The only downside for me is it that it’s held on Thursdays and Fridays, which means I can join up only after work. Blah.

All in all - more than 130 closed issues - w00t!

So yep, see you all in December on the fourth Bug Hunt days ;)

Happy hacking!

Tags: bug, framework, hunt, zend.
Categories: Development, Programming.

Zend Framework 1.8 Web Application Development book review

by Robert Basic on November 17, 2009.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

A few days ago I finished reading Keith Pope’s book titled “Zend Framework 1.8 Web Application Development”, so, after letting it “rest” in my mind for a while, here are my thoughts on it…

First, I must point out the “language” of the book - I was expecting a text that’s hard to follow, that’s full of words and sentences requiring at least two dictionaries by my side to help me out (hey, English is not my first language!), but, it was quite an easy and, if I may add, an enjoyable read.

If you think, that you’re just gonna sit down, read the book and know all about Zend Framework, boy you’re wrong! Yes, the book explains a lot, but you’ll still need to follow the example codes along the way and play with them to get really familiar with ZF.

The book starts off with a basic application (yep, “Hello world!”), explains the bootstrapping, configuring, working with action controllers, views and handling errors… The second chapter continues with explaining the MVC architecture, the front controller, router, dispatcher… It even has a nice flowchart about the whole dispatch process, great stuff.

From chapter 3 to chapter 12, the author is taking you through a process of building a web application – from creating the basic directory structure, over the hardcore programming stuff to the optimizing/testing part. Chapter 4 gives a rather good explanation on the “Fat Model Skinny Controller” concept; chapter 8 deals with authentication and authorization; chapter 11 takes care of the optimization.

At last, my favourite part of the book is when the author has several “ways out of a problem”, he tells the good and the bad sides of each, picks out the best one and explains why did he choose that particular one. I hate it when an author just simply says: “This is the right way, trust me.”, without caring to explain why.

So, would I recommend this book to a friend who wants to start working with ZF? Absolutely.

Also, be sure to check out what Jani, Raphael, Rob and Sudheer have to say about this book (Jani’s and Rob’s reviews are not up yet, so I’m linking to their feeds!), too.

Happy reading! :)

Edit 2009., November 23rd: Added a link Sudheer’s post :)

Tags: book, framework, php, review, zend.
Categories: Development, Programming.