Developing software in the Real World

Exploring Zend_Paginator

One area of displaying lists on web pages that I've generally disliked doing is pagination as it's a bit of a faff. Recently, I needed to do just this though as I couldn't delegate it as my colleague was too busy on other work. As a result, I thought that I should look into Zend_Paginator this time. Turns out that it's really easy to use and the documentation is great too. The really useful thing… continue reading.

A Zend Framwork compound form element for dates

A while ago I needed to ask a user for their date of birth on a Zend_Form. The design showed three separate select elements to do this: A little bit of googling found this site which has now unfortunately disappeared, so the code in this article owes a lot of the author of that article. It turns out to be remarkably simple to create a single Zend Form element that is rendered as multiple… continue reading.

Zend Framework View Helpers

I can't seem to find an article here that consolidates my thoughts on Zend Framework's view helper system, so I thought I'd better correct that. Zend Framework's Zend_View component supports helper methods known as view helpers. They are used like this in a view script: <?php echo $this->myHelper('myParam1'); ?> Behind the scenes, this is implemented as a method within a class something like this: <?php class Zend_View_Helper_MyHelper extends Zend_View_Helper_Abstract { public function myHelper($myParam1) { $html… continue reading.

Using your own View object with Zend_Application

Let's say that you want to use your own view object within your Zend Framework application. Creating the view object is easy enough in library/App/View.php: class App_View extends Zend_View { // custom methods here } along with adding the App_ namespace to the the autoloader in application.ini: autoloadernamespaces[] = "App_" All we need to now is get Zend_Application to bootstrap with our new view class. There are two ways of doing this: within Bootstrap.php or… continue reading.

Translations of my Zend Framework Tutorial for ZF 1.10 & 1.11

Recently, a couple of people have very generously donated their time to translate my Zend Framework Tutorial into their native language to help their fellow countrymen. Firstly, Mario Santagiuliana has provided an Italian translation: Introduzione allo Zend Framework. Secondly, Radosław Benkel translated into Polish and I'm hosting the PDF here: Pierwsze kroki z Zend Framework.pdf. Thank you both!

Remove index.php from your URL

One thing you may have noticed with Zend Framework projects that use the baseUrl() view helper to reference CSS and other static files is that it doesn't work if the URL contains contains index.php. Let's explain, by using code from the tutorial. In the layout.phtml file, we link to a CSS file like this: <?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/site.css'); ?> This code uses a baseUrl() view helper that looks like this <?php class Zend_View_Helper_BaseUrl { function baseUrl()… continue reading.

Enrise: Using MemCacheQ as a Message Queue

Tim de Pater of Enrise has written a new article on how to integrate MemCacheQ with Zend Framework application using Zend_Queue_Adapter_Memcacheq component: For (a Dutch newspaper) we wanted a simple and free queue mechanism that integrates with Zend Framework for handling a number of jobs. We found MemcacheQ. The article then goes through how to run the memcacheq daemon and then shows the PHP code to add a job to the queue and then… continue reading.

Handling exceptions in a Front Controller plugin

If you have a Zend Framework Front Controller plugin which throws an exception, then the action is still executed and then the error action is then called, so that the displayed output shows two actions rendered, with two layouts also rendered. This is almost certainly not what you want or what you expected. This is how to handle errors in a Front Controller plugin: Prefer preDispatch() over dispatchLoopStartup() as it is called from within the… continue reading.

David Papadogiannakis: HTML5 Zend Framework form elements

David Papadogiannakis has posted a new article on the new features for forms with HTML5 and how it applies to Zend Framework's Zend_Form component. HTML4 had a few different input elements that could be added to your form : text, password, hidden, checkboxes etc. HTML5 brings even more types that can be added to your <input> tag. He then goes on to provide an override to Zend_Form_Element_Text showing how to use the new attributes with… continue reading.

View helpers in modules

I came across a situation last week where I needed to access a view helper that was in the default module's views/helpers directory when I was in another module. This came about because my layout.phtml uses a view helper that is in application/views/helpers. By default, it doesn't work and you get an error along the lines of:

The fix is simple enough. All you need to do is add this line to your application.ini… continue reading.