<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Musings &#187; zend_paginator</title>
	<atom:link href="http://cbeer.info/blog/tag/zend_paginator/feed/" rel="self" type="application/rss+xml" />
	<link>http://cbeer.info/blog</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 22:14:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Zend Framework 1.6: Zend_Paginator</title>
		<link>http://cbeer.info/blog/2008/07/29/zend-framework-1-6-zend_paginator/</link>
		<comments>http://cbeer.info/blog/2008/07/29/zend-framework-1-6-zend_paginator/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 22:22:50 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_paginator]]></category>

		<guid isPermaLink="false">http://192.168.2.101/wordpress/?p=17</guid>
		<description><![CDATA[The new Zend Framework 1.6 release candidate includes a Zend_Paginator class, which is an excellent thing to have around because I know I‚Äôve re-invented that wheel on every site I‚Äôve developed. My only criticism of the new Zend_Paginator is it &#8230; <a href="http://cbeer.info/blog/2008/07/29/zend-framework-1-6-zend_paginator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The new Zend Framework 1.6 release candidate includes a <a href="http://framework.zend.com/manual/en/zend.paginator.html">Zend_Paginator </a>class, which is an excellent thing to have around because I know I‚Äôve re-invented that wheel on every site I‚Äôve developed. My only criticism of the new Zend_Paginator is it offers a daunting amount of possibilities. </p>
<p>To that end, here‚Äôs a quick cheat sheet to get things up and running:</p>
<p>First, we need to establish the data source and initialize the paginator</p>
<pre name="code" class="php">class EventController {
    public function listAction() {
        //get an array of events
        $arrEvents = Core::Event::fetch_by_filter(array('link' =&gt; array('child' =&gt; $objCharacter), 'eventExpire' =&gt; time()));
       //initialize the paginator using the handy factory method..
        $paginator = Zend_Paginator::factory($arrEvents);
        //tell the paginator which page we're on
	$paginator-&gt;setCurrentPageNumber($this-&gt;_getParam('page'));
        //pass the paginator into the view
	$this-&gt;view-&gt;paginator = $paginator;
    }
}
</pre>
<p>Then we need to put the paginator to use:</p>
<pre name="code" class="php">&lt; ?php if (count($this-&gt;paginator)): ?&gt;
<ul>
&lt; ?php foreach ($this-&gt;paginator as $item): ?&gt;
<li>
<h3>&lt; ?php echo $item-&gt;title; ?&gt;</h3>
<div>&lt; ?php echo $item-&gt;message ?&gt;</div>
</li>

&lt; ?php endforeach; ?&gt;
</ul>

&lt; ?php endif; ?&gt;

&lt; ?= $this-&gt;paginationControl($this-&gt;paginator, 'Sliding', 'pagination_control.phtml'); ?&gt;
</pre>
<p>Then, we need to create the pagination control (surely this could be a view helper?). The manual page for Zend_Paginator provides a number of different examples. I‚Äôve chosen to use the sliding control just for aesthetic purposes:</p>
<pre name="code" class="php">&lt; ?php if ($this-&gt;pageCount): ?&gt;
<div id="paginationControl">
&lt; ?= $this-&gt;firstItemNumber; ?&gt; - &lt; ?= $this-&gt;lastItemNumber; ?&gt;
of &lt; ?= $this-&gt;totalItemCount; ?&gt;

&lt;a href="&lt; ?= $this-&gt;url(array('page' =&gt; $this-&gt;first)); ?&gt;"&gt;First&lt;/a&gt; |

<!-- Previous page link -->
&lt; ?php if (isset($this-&gt;previous)): ?&gt;
  &lt;a href="&lt; ?= $this-&gt;url(array('page' =&gt; $this-&gt;previous)); ?&gt;"&gt;&lt; Previous&lt;/a&gt; |
&lt; ?php else: ?&gt;
  &lt;span class="disabled"&gt;&lt; Previous&lt;/span&gt; |
&lt; ?php endif; ?&gt;

<!-- Next page link -->
&lt; ?php if (isset($this-&gt;next)): ?&gt;
  &lt;a href="&lt; ?= $this-&gt;url(array('page' =&gt; $this-&gt;next)); ?&gt;"&gt;Next &gt;&lt;/a&gt; |
&lt; ?php else: ?&gt;
  &lt;span class="disabled"&gt;Next &gt;&lt;/span&gt; |
&lt; ?php endif; ?&gt;

&lt;a href="&lt; ?= $this-&gt;url(array('page' =&gt; $this-&gt;last)); ?&gt;"&gt;Last&lt;/a&gt;
</div>

&lt; ?php endif; ?&gt;
</pre>
<p>Finally, a quick little Zend_Router route to pretty up the URL:</p>
<pre name="code" class="php">$router-&gt;addRoute('event_list', new Zend_Controller_Router_Route('event/list/:page', array('controller' =&gt; 'event', 'action' =&gt; 'list')));
</pre>
<p>Now, when you navigate to /event/list/1, you have a paginated list (unstyled):</p>
]]></content:encoded>
			<wfw:commentRss>http://cbeer.info/blog/2008/07/29/zend-framework-1-6-zend_paginator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
