Pragmatism in the real world

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: Plugin by name 'LoggedInAs' was not found in the registry; used paths: Plan_View_Helper_: /www/funkymongoose/habuplan/application/modules/plan/views/helpers/ Zend_View_Helper_: Zend/View/Helper/ The fix… continue reading.

PHP 5.3 is quicker than PHP 5.2

I know that everyone already knows this, but I happened to find out for myself recently! I was looking at the way view helpers work in ZF2 and thought it would be more convenient if we altered the syntax a little. A side-effect of the change was that we'd have to use call_user_func_array, which is perceived as slow. I thought I'd whip up a simple test to find out how much slower it would be… continue reading.

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.

Some notes on SQL Server blobs with sqlsrv

I recently updated my use of SQL Server with Zend_Db_Adapter_Sqlsrv to use UTF-8 throughout. This turned out to be easy enough: Use ntext, nvarchar types in the database add: resources.db.params.driver_options.CharacterSet = "UTF-8" to your application.ini I subsequently noticed a problem with storing binary data to a varbinary(max) field. The error was: An error occurred translating string for input param 2 to UCS-2: No mapping for the Unicode character exists in the target multi-byte code page.… 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.

I'm speaking at PHPBenelux Conference 2011

I'm delighted to be able to announce that I'm speaking at the PHPBenelux Conference on 28 & 29 January 2011 in Antwerp, Belgium. This is a community run conference organised by the PHPBenelux user group and given the list of speakers, I'm expecting to learn a lot. The full list of talks is on their website and shows that this is going to be a great conference. I'll be giving a talk that will introduce… continue reading.

SqlSrv v2 and long field names

A good proportion of the projects my company undertakes end up on Windows servers with IIS and SQL Server and hence we use the SqlSrv PHP extension from Microsoft. We don't host any of these projects ourselves and leave it up to the client's IT department. This is the main reason that we use a database abstraction layer, Zend_Db, in our case as we can swap the underlying database out with less hassle. A couple… continue reading.

PHPNW10 Conference

The PHPNW Conference is an annual conference held in Manchester, now in its 3rd year and again I was invited to speak. The organisation of PHPNW was top-notch as usual with everything running smoothly from my point of view. I'm sure there were a few hectic moments for the organisers though :) The day started with Lorna's keynote on how to improve your skill set as a team. This was a great talk which sparked… continue reading.