Software for the web

Hello and welcome to AVNet Labs, my portfolio and blog. I build accessible and standards-compliant websites and web applications that account for speed, accessibility and usability while adhering to web standards.

Latest journal entries

Zend_Db_Table dynamic finders

June 15th, 2009

The recently added Zend_Navigation component uses dynamic finders to find pages e.g. findOneByLabel('Home') to return the first matching page with label Home (and that's straight from the manual).
It would be nice if Zend_Db_Table could do this too but it can't. This seems a little inconsistent to me. Why do it for some components and not others?

Anyway, adding it wasn't that difficult. The first step is to have an (abstract?) class extend Zend_DB_Table and let all your Db-backed models extend that. I'll call mine App_Db_Table.

[php] <?php abstract class App_Db_Table extends Zend_Db_Table_Abstract { /** * Db Instance */ protected $_db; /** * Call method used to implement the dynamic finders * * @param string * @param array * @return function || void */ public ...

Zend Framework deployment with Capistrano

May 8th, 2009
After playing around with Phing for a while I decided to bring the simplicity of Capistrano - which I have been using with my Rails apps - to our Zend Framework project at work. Surprisingly it wasn't hard at all. "Capistrano is a tool for automating tasks on one or more remote servers". That's straight off their website and this tool rocks. Capistrano is written in Ruby and needs the ruby library to be installed on the client machine. It does not need ruby on the production or any other target servers and at work we deploy from two machines and needed ruby installed on just the two. However the ruby files for the deployment recipes need to be ...

Zend Framework and the cost of flexibility

May 7th, 2009
I have had to downgrade my copy of the Zend Framework to 1.7.8 after 5 mins of 'upgrading' to 1.8.0 to get access to all the promised goodies (Zend Tool, Zend Application, Zend Navigation, etc). Unfortunately, Zend_Loader::registerAutoload has been deprecated and I got notices all over my screen. Considering we are working on multiple projects in Zend Framework and we all have local copies I didn't think it was such a good idea recommending this upgrade to the team especially with deadlines looming really close. However, I don't think I'll be missing any of the new additions considering the hassle involved in using them. Why must everything be so complex in ZF? I copied over the CLI tool forĀ  a ...

Rails makes you think you can

April 21st, 2009

I spent a couple of hours last weekend going over a Rails app I wrote almost two years ago. It was the very first Rails application I had written (apart from the follow-the-screencast throwaway ones) and I couldn't help cringing when I saw the code I got paid good money to write.

That app is still my most ambitious project ever and I'm still shocked I decided to do it in Ruby (a language I barely knew) and Rails (after playing with it for a few weeks) when I had a couple of years experience in PHP and some production apps already running on CodeIgniter. I guess it was the hype.
However, almost two years later and the app is still ...

Finally… passenger for nginx

April 17th, 2009

I just spent last weekend setting up a new slice at SliceHost (my bestest host ever) for a couple of Rails apps only to read this post announcing the release of Phusion Passenger for Nginx.

Considering I only needed the slice for Rails (No php and the DB is on another slice), I could have gone with Nginx except that I've been spoilt by Passenger's upload-and-go deployment and being able to squeeze more apps into a small VPS (the inactive ones shut down and release memory). Now hopefully, it's the best of both worlds.

I'll still have to learn Nginx quirks considering I've always used Apache but the promise of faster page serving and a lower memory footprint is ...

Jazz up your phpunit test results

February 1st, 2009
I use RedGreen when working on rails projects and have gotten used to the visual feedback I get when tests pass or fail. It has definitely helped with my Red-Green-Refactor flow. I just found out phpunit supports colors in tests and it's built-in as well. No gem installation required. Sweet! Turning on colours is done either with a command line argument or by adding an attribute to the phpunit XML configuration file. Command Line: phpunit --colors testfile.php XML File: [xml] <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true"> <testsuite name="All Tests"> <directory>./</directory> </testsuite> </phpunit> [/xml]
  • No Colours: No colour
  • Passing Tests - with colours: Passing Tests
  • Failing Tests - with colours: Failing Tests
  • Skipped or Incomplete Tests - with colours:...

Jara Base – a base Zend Framework app

January 21st, 2009

I recently had to set up a Zend Framework project at a friend's house and realized how reliant I am on Zend Studio to set up a fresh project. Meet Jara Base - the ZF starter app and my solution to this minor issue. It's essentially a slightly modified version of the Zend Studio project structure with the following variations/additions:

  • Defined an APP_ROOT constant. I have needed access to the application root a number of times and it was a choice between adding it to the Registry or using a constant.
  • Defined an APP_ENV constant. This defaults to development and is set to test when the unit tests are running.
  • Added include paths ...

Zend Framework titbits

January 18th, 2009
There are a couple of Zend Framework snippets and how-tos I find myself googling over and over again. I have decided to maintain this list and keep adding to it as I go along.
  • Bypassing Zend_Db prepared statements:For complex queries, you may have to write the query out by hand and we recently had to do that. However Zend_Db insists on preparing ALL statements and a PDO bug forced the need to bypass this by accessing the connection object directly. To do that run: [bash toolbar="false"]$result = $db->getConnection()->exec('SELECT * FROM users');[/bash]

    More in the documentation

  • Disable Zend_Layout [php] public function ajaxAction() { // disable layouts for this action: $this->_helper->layout->disableLayout(); ... } [/php]
  • Disable Zend_ViewRenderer [php] public function processingAction() { $this->_helper->layout->disableLayout(); // disable the view for this action. e.g. actions that redirect ...