Posts from June 2009

Using Twitter as a voting platform

Cast of Star Trek

Like a lot of other people, I've had a love/hate relationship with Twitter. At first I didn't see the point - it was just Facebook without the features, then I drank the kool-aid, and fell in love with its simplicity and openness. Nowadays I've backed off a bit and see it as an interesting social phenomenon that I enjoy being a part of. I'd been meaning to check out the Zend_Service_Twitter PHP library for a while, but hadn't really thought of an excuse.

A few weeks back I was unlucky enough to watch Star Trek V and tweeted about how crap it was, despite my friend Nick thinking it's the best of the lot. There was a bit of back and forth, so I posted an order for the films, from best to worst. A few of my friends then did the same, with the hashtag of #startrekrank as a way of identifying the posts.

It struck me that I could somehow aggregate these results using the Twitter API, so I present to you, StarTrekRank.com!

Simplify pagination logic using a custom Zend_Paginator_Adapter

Pagination logic is something that I've found myself redoing a number of times over the years, and each time it's been a relatively fiddly and painful process.

This time around I decided to check out the Zend_Paginator component from the Zend Framework, and found the process useful enough to share! In my case I was using Doctrine to retrieve data from the database. I'll skip most of the Doctrine-specific stuff, however, as hopefully this will end up as a decent example of how to integrate Paginator with other non-Zend libraries.

When the Paginator is instanced, it's given an instance of an appropriate Adapter and told what the current page is:

<?php
$paginator 
=  new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(20);
$paginator->setCurrentPageNumber(2);