Posts tagged with 'zend-framework'

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);

Keeping querystrings clean with Zend Framework

I'm something of a zealot about short, readable URLs. Most people by now are using server rewrite rules and Front Controllers of some sort to keep the paths in their application sane and legible, but an area that's often overlooked is the querystring, especially after a form submission.

A typical example of a situation with a 'messy' querystring might be a search form on site. When a form is submitted, all the elements in the form are entered into the querystring whether they're relevant or not.

That leads to querystrings like /search?size=&shape=&colour=red&age=, which would be a lot more legible as /search?colour=red

On some sites I work with, an 'advanced search form' can have up to 20 elements, all of which might get submitted in one go leaving the search results page with a huge URL.