Using Zend_Paginator with Twitter API and Zend_Cache

Zend Framework 1.10.0 is out and a comment was posted on my blog that lead me to creating this new post. I’m going to focus more on Zend_Paginator and Zend_Rest_Client to access Twitters API since I’ve already created a post on Zend_Cache. Normally, I would use Zend_Service_Twitter to access the twitter service but it still seems to require authentication to retrieve a users timeline where only protected users should require authentication.

Zend_Paginator

Zend_Paginator from the Zend Framework site:

Zend_Paginator is a flexible component for paginating collections of data and presenting that data to users.

Zend_Paginator automatically creates pagination for you by setting up a few parameters and passing it an array of data. What is pagination, if you have ever gone to Google and searched for anything, usually you’ll see something like the following at the bottom of the search results page:

See the numbers and the text links, this is called pagination. So much data exists for the particular search that it wouldn’t make sense to display it all in one page. It would cause large amounts of scrolling down to view, the load time of the page would be affected, so we rather show fewer results and give our users the option of viewing more by clicking on the pagination links.

To demonstrate how to use Zend_Paginator I created a sample Zend Framework 1.10.0 application. This application grabs my last 50 tweets using the Twitter API and displays them 10 at a time using Zend_Paginator. I use Zend_Cache to cache my twitter data so I don’t have to spend time accessing their api every time – I’m sure they would appreciate it.

Bootstrap

The first step was to create a new zend framework project. I’m making the assumption that if you are reading this then you already know how to do this. After creating my new project, I added two methods to my bootstrap file to autoload and to init Zend_Cache. My bootstrap looks like the following:
Continue reading “Using Zend_Paginator with Twitter API and Zend_Cache”