Developing software in the Real World

Local config files and Zend_Application

A friend of mine recently had a requirement where she wanted to have two config files loaded into Zend_Application, so that the specific settings for the server were not stored in the version control system. Hence she has two config files: application.ini and local.ini where local.ini is different on each server. Update: As takeshin points out with ZF 1.10 or later, an easier solution to this is to pass both ini files into Zend_Application: $application… continue reading.

Ralph Schindler: Composite Rowsets For Many-To-Many Relationships Via Zend_Db_Table

Ralph has just posted an excellent article on how many to many relationships work with Zend_Db_Table: Basically, I’ve created a single class that effectively take the place of Zend_Db_Table_Row::findManyToManyRowset() for the purposes of creating an iterable rowset that allows access to both the target many-to-many rowset as well as the junction rowset. This solution is called a Composite Rowset. In this solution, both rowsets (iterators) are kept in sync with one another. This proves to… continue reading.

Validating UK Postcodes

I'm sure everyone else already knows this, but I've recently discovered that Zend_Validate_PostCode doesn't work with UK postcodes unless you first remove the space between the first and second parts. This is due to a bug in the underlying regular expresssions that are provided by CLDR. It's easy enough to add a filter to remove the space, but I'm a little worried that when (and if) it gets fixed, will the fixed version Zend_Validate_PostCode then… continue reading.

Validating dates

I discovered recently that Zend Framework 1's Zend_Date has two operating modes when it comes to format specifiers: iso and php, where iso is the default. When using Zend_Validate_Date in forms, I like to use the php format specifiers as they are what I'm used to and so can easily know what they mean when reviewing code that I wrote months ago. My code looks something like this: $subForm->addElement('text', 'start_date', array( 'filters' => array('StringTrim', 'StripTags'),… continue reading.

A form in your layout

I recently received an email asking for my advice about how to handle a form that appears on every page. I want to add a newsletter sign up box to layout.phtml so it will appear on every page. The layout->content() comes from several different action controllers… So how do I handle the newsletter sign up? I thought that the answer is long-winded enough to be worth writing a blog post about. One way to do… continue reading.

Devzone article on Zend_Config

Vikram Vaswani has written an article on Manipulating Configuration Data with Zend_Config. Zend_Config seemed to meet my needs, so I played with it a little and then deployed it in a couple of projects. It did everything I needed it to, and was easy to integrate with both framework and non-framework PHP projects. It also has a couple of neat features, such as the ability to merge multiple configurations together. Keep reading and I'll give… continue reading.

ZendTool providers in ZF2 (dev1)

I've started playing with the development versions of ZF 2.0 and one of the first things I thought I'd do was to port Akrabat_Db_Schema_Manager. It turned out to be reasonably easy. All I needed to do was rework my use of ZF components to use the new ZF2 ones. Whilst I was at it, I also converted it to use namespaces. I also had to reorganise the library so that I could have ZF1… continue reading.

Setting up ZF2's ZendTool side by side with ZF1

Note: this article does not refer to the released version of Zend Framework 2!. If you want to play with the development versions of Zend Framework 2.0, then it's handy to be able to create ZF2 projects using the ZendTool command line tool. Rather unhelpfully, ZF2's ZendTool uses the same ini file (~/.zf.ini) as ZF1's Zend_Tool and the same script filename, so you can't just put zf2 on to your path and it'll all… continue reading.

TweetGT: an example of Zend_Service_Twitter via OAuth

TweetGT is a simple application that talks to Twitter. I wrote it as I couldn't find another way to send a geotagged tweet sent from an arbitrary location. Also, my friend Cal Evans says that writing a Twitter app is the new Hello World, so I thought I'd better find out how to do it! Obviously, I used Zend Framework :) The source is up on github so you can have a look at the… continue reading.

Unit testing controller actions with Zend_Test_PHPUnit_ControllerTestCase

Testing controllers has traditionally been a hassle due to the requirements of setting up the bootstrap, the front controller and initiating the dispatch cycle. In June, Matthew addressed this with the release of Zend_Test_PHPUnit_ControllerTestCase way back in 2008. Later, Matthew helpfully wrote an article on how to use it and I have used that as a starting point for the information here. (Thanks Matthew!) The project I'm using is TodoIt, which is a simple ZF… continue reading.