Zend_Controller

Bradley Holt’s Blog: Front Controller Pattern in Zend Framework

After giving a presentation about Zend Framework Bradley Holt realized that there is often too much material to cover in the time available. His takeaway was to start blogging about Zend Framework. In is first post in the series about Zend Framework he talks about front controller implementation in Zend Framework.

Like many other frameworks, Zend Framework provides an implementation of the Front Controller pattern. This means that all HTTP requests can be sent through a centralized point. This allows you to take advantage of Zend Framework’s routing and Model-View-Controller (MVC) components, if you so choose.

Robert Basic’s Blog: Chaining routes in Zend Framework

There are commonly know features of Zend Framework, and some tiny ones that pass unnoticed until one wants something specific. One of such features are routes chains. Robert Basic wrote quick and simple tutorial about chaining routes through another one, to create multilanguage website URLs:

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 :) (..) 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.

Interested how Robert did it? Follow to his blog, see his 30-line code and think about all other possibilities.

Giorgio Sironi’s Blog: How not to test controllers

There has been lots post published about unit testing in Zend Framework recently. Most of them show how to setup simple testing environment and write simple test. In his recent post Giorgi Sironi shows how not to test Zend Framework action controllers.

Yesterday on twitter a discussion started about how to properly design Zend Framework action controllers to allow simplicity of testing, specifically how to inject collaborators in controllers and to avoid breaking the law of Demeter.

Presented real life example seems to be simple and typical. Giorgio explains what is wrong about it and what kind of obstacles from unit testing point of view it creates. The post is not only about how no to test controllers but also about what controllers should and should not do.

Update

Giorgio’s post has its continuation, where he explains why we can drop unit testing controllers and what controllers really do.

Update 2

Giorgio published another follow up to his, as we see controversial, post.

Federico Cargnelutti’s Blog: Testing Zend Framework Action Controllers With Mocks

Testing Zend Framework can be very tricky. The team tries to make framework based applications as much testable as possible, but there are still parts of Zend Framework’s written the way it’s hard to test code based on it. Recently Georgio Sironi was writing about testing view helpers. Today Federico Cargnelutti writes about testing action controllers using mocks.

Unit testing controllers independently has a number of advantages:

  1. You can develop controllers test-first (TDD).
  2. It allows you to develop and test all of your controller code before developing any of the view scripts.
  3. It helps you quickly identify problems in the controller, rather than problems in one of the combination of Model, View and Controller.

What is very interesting about Federico’s post, is that he not only shows example test, but also points reader to some framework’s known issues preventing developers to test particular things. Naturally solution for mention issues is also provided.

Export Excel Spreadsheets using Zend Framework and Spreadsheet_Excel_Writer

In the new post on his blog, Pablo Viquez writes about exporting data to Excel spreadsheet using Zend Framework and Spreadcheet_Excel_Writer (PEAR component). Most interesting part of article, at least for me, is context switching.

Zend Framework offers a nice feature called “Context Switch”. This is an action helper that detects requested output and calls the specific view for the required format.

Presented layout and multi-context application and explanation of how to plug-in contexts not supported by default by Zend Framework is a must ready for everyone looking for clear solutions of presenting same data in different format.