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”

Finally gave my blog a much needed face lift!

So what do you guys think? Does it look better now? It is not finished, I still need to tweak some graphics and colors but overall I’m very pleased. I started out with a new theme: Arclite by digitalnature. It has many customization options so I haven’t had to do too much tweaking of the .css files but there has been some. Since I blog so much about code, I finally stopped being lazy and got a code highlighter. I’m using: Dean’s Code Highlighter by Dean Lee. It’s very easy to use and supports a range of different code syntax such as PHP and Actionscript. One of the reasons I decided to update my look was because I have been running an older version of WordPress and it was about time to upgrade. I’m now running 2.9.1 and it looks great. I really like the new admin back office and it is so easy to use and setup.

I also created my first widgets! The ‘Interesting Links’ and ‘Interesting Images’ on the sidebar are no longer hacks done on the themes sidebar.php file. I learned how to create a plugin in WordPress and make it into a widget. Here is what one of the widgets looks like:

/*
Plugin Name: JR-Images
Plugin URI: http://www.joeyrivera.com
Description: Show my images
Version: 0.1
Author: Joey Rivera
Author URI: http://www.joeyrivera.com

  Copyright 2010  Joey Rivera  (email : joey1.rivera@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
 
function show_images() 
{
	global $wpdb;
	
	$query = '
		SELECT image_file, image_origin, image_thumbnail
		FROM wp_images
		ORDER BY image_id DESC
		LIMIT 6';
	
	$results = $wpdb->get_results($query);
	
	if(!$results)
	{
		return;
	}
	echo '
  • Interesting Images

    '; echo '
      '; foreach($results as $row) { echo '
    • ', "\n"; } echo '
    '; echo '
  • '; } function register_images() { register_sidebar_widget("JR-Images", "show_images"); } add_action("plugins_loaded", "register_images");

    I had to go back to all my old posts and make updates. If you find any issues anywhere, please let me know so I can fix it asap. I’ve found instances in code where there should be two && and instead the code blocks shows &&. I’m currently trying to figure out why my preview button doesn’t work, hopefully I’ll figure that out soon so I can move on to changing some colors around and finally updating my ‘About Me’ page. I hope to have some content in that page by the end of this weekend. Other than that, I hope you all enjoy the new look and am looking forward to hearing some feedback!