<?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>The Zend Framework in Practice</title>
	<atom:link href="http://zf.gm-ram.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zf.gm-ram.com</link>
	<description>Developing Web Applications with the Zend Framework</description>
	<lastBuildDate>Wed, 01 Sep 2010 16:54:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Zend_Cache with Zend_Feed</title>
		<link>http://zf.gm-ram.com/posts/using-zend_cache-with-zend_feed/</link>
		<comments>http://zf.gm-ram.com/posts/using-zend_cache-with-zend_feed/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 17:58:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_Cache]]></category>
		<category><![CDATA[Zend_Feed]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=715</guid>
		<description><![CDATA[I have described how to use Zend_Feed to retrieve a digest of a blog&#8217;s latest entries in a previous post. In the overall implementation described in my series of posts, this digest is fetched every time a page is loaded. Although, by using AJAX techniques, this does not slow the loading of the basic page, [...]]]></description>
			<content:encoded><![CDATA[<p>I have described how to use Zend_Feed to retrieve a digest of a blog&#8217;s latest entries in a <a href="http://zf.gm-ram.com/posts/the-blogs-page-the-feed-digest-view-helper/">previous post</a>. In the overall implementation described in my series of posts, this digest is fetched every time a page is loaded. Although, by using AJAX techniques, this does not slow the loading of the basic page, it does result in some unnecessary repetitive work, since the blogs are not updated that often. In this post, I shall look at how I am using caching on the recently revamped <a href="http://www.gm-ram.com/">GM-RAM website</a> to save the results and reuse them.<span id="more-715"></span></p>
<p>Here is the basic skeleton of the new feed controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> FeedController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> digestAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// TODO: Insert digest action handling code here</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// TODO: Insert any additional member functions here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The controller contains one action handler, for the digest action.</p>
<p>The implementation of the action handler starts by disabling the standard layout, as it is an AJAX request:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It then tries to get the blog ID. If it cannot, it reports an error; if it can, it then tries to fetch the digest for the log.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Get the blog ID</span>
    <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      try
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// TODO: Insert code to fetch blog digest and pass it to the view here</span>
      <span style="color: #009900;">&#125;</span>
      catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Log the error</span>
        <span style="color: #000088;">$log</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'log'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">err</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error retrieving feed - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Report the error</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Error retrieving feed'</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Blog ID not specified'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note that the process of fetching the digest is wrapped in a try/catch block to handle any errors; these are logged in detail.</p>
<p>Now we go through a two stage process:</p>
<ol>
<li>First we check whether the digest for the specified blog ID is in the cache; if it is, we use that</li>
<li>However, if it it not, we retrieve the feed URL from the database, then fetch the digest from the feed</li>
</ol>
<p>In both cases, either the digest is passed to the view script, or an error message, should an error occur.</p>
<p>The implementation of this is given below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #666666; font-style: italic;">// See if we can get the feed info from the cache</span>
        <span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digest</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'feed_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// Get the blog information from the database</span>
          <span style="color: #000088;">$dbTableBlog</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Application_Model_DbTable_Blog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbTableBlog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbTableBlog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchRow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Get the blog digest from the feed and cache it</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digest</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feedDigest</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digest</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'feed_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #b1b100;">else</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Blog ID not found in database'</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The cache object is created by a call to the following private member function of the controller&#8217;s class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _getCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Set the cache frontend and backend options</span>
    <span style="color: #000088;">$frontendOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'lifetime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">7200</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Cache lifetime of 2 hours</span>
      <span style="color: #0000ff;">'automatic_serialization'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$backendOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'cache_dir'</span> <span style="color: #339933;">=&gt;</span> APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cache/'</span> 
        <span style="color: #666666; font-style: italic;">// Directory where to put the cache files</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get a Zend_Cache_Core object</span>
    <span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> Zend_Cache<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Core'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'File'</span><span style="color: #339933;">,</span> 
      <span style="color: #000088;">$frontendOptions</span><span style="color: #339933;">,</span> <span style="color: #000088;">$backendOptions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note that we need to configure a front end and back end for the cache. The former is concerned with things like the lifetime of the cache, the latter with where the cached data is stored.</p>
<p>The view script is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>APPLICATION_ENV <span style="color: #339933;">==</span> <span style="color: #0000ff;">'development'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;error&quot;&gt;%s&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;No posts found&lt;/p&gt;'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digest</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;No posts found&lt;/p&gt;'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note that the script is set to render a more descriptive error message in development mode, to assist with debugging. Otherwise, the script should be self-explanatory.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/using-zend_cache-with-zend_feed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GM-RAM Website Revamped</title>
		<link>http://zf.gm-ram.com/posts/gm-ram-website-revamped/</link>
		<comments>http://zf.gm-ram.com/posts/gm-ram-website-revamped/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 22:47:27 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[GM-RAM Website]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=703</guid>
		<description><![CDATA[I have just put up the latest version of the GM-RAM website. In appearance, it is very similar to the old site; the main visual changes have been the switch to a three column layout, and the decision to dispense with jQuery UI tabs on the site pages. The content has hopefully been improved to [...]]]></description>
			<content:encoded><![CDATA[<p>I have just put up the latest version of the <a href="http://www.gm-ram.com/">GM-RAM website</a>. In appearance, it is very similar to the old site; the main visual changes have been the switch to a three column layout, and the decision to dispense with jQuery UI tabs on the site pages. The content has hopefully been improved to make it clearer what GM-RAM does, including some of the projects we have been involed in.<span id="more-703"></span></p>
<p>Some of the more recent articles I have written have already touched on some of the things I have been adding to the site; see the <a href="http://zf.gm-ram.com/posts/pagination-using-zend_paginator/">post on pagination</a>, the <a href="http://zf.gm-ram.com/posts/a-custom-resource-plugin-for-populating-the-registry/">post on a plugin to populate the registry</a> and the <a href="http://zf.gm-ram.com/posts/adding-an-automatically-generated-sitemap-xml-to-a-zend-framework-site/">post on automatically generating a sitemap</a>. I intend to do some further posts on the new parts of the site implementation that are of wider interest.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/gm-ram-website-revamped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an automatically-generated sitemap.xml to a Zend Framework site</title>
		<link>http://zf.gm-ram.com/posts/adding-an-automatically-generated-sitemap-xml-to-a-zend-framework-site/</link>
		<comments>http://zf.gm-ram.com/posts/adding-an-automatically-generated-sitemap-xml-to-a-zend-framework-site/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 17:08:32 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_Controller]]></category>
		<category><![CDATA[Zend_Navigation]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=695</guid>
		<description><![CDATA[This article looks at how to dynamically create a Google sitemap.xml file for your Zend Framework site. It assumes that you are using Zend_Navigation to describe the basic layout of your site. It also assumes that the application is based on Zend_Application and uses Zend_Layout. First, we need to create the controller class used to [...]]]></description>
			<content:encoded><![CDATA[<p>This article looks at how to dynamically create a Google <em>sitemap.xml</em> file for your Zend Framework site. It assumes that you are using Zend_Navigation to describe the basic layout of your site. It also assumes that the application is based on Zend_Application and uses Zend_Layout.<span id="more-695"></span></p>
<p>First, we need to create the controller class used to field the request for the sitemap. This is called <strong>SitemapController</strong> and is located in <em>controllers/SitemapController.php</em>. The class has the following skeleton:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> SitemapController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// TODO: Implement the class action handlers here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The first action is the <strong>index</strong> action, which is handled by the follow method of the class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This disable the standard layout, so that only the XML of the sitemap is rendered.</p>
<p>The accompanying view script file is <em>application/views/scripts/sitemap/index.phtml</em> and contains the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sitemap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFormatOutput</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sitemap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This takes the pages in the navigator and uses them to generate a sitemap.</p>
<p>Now, if you navigate to <strong>http://<em>[your-domain]</em>/sitemap</strong>, the sitemap will be rendered in the browser.</p>
<p>Now we need to set up the router, so that a request for <strong>http://<em>[your-domain]</em>/sitemap.xml</strong> also brings up the sitemap.</p>
<p>To do this, we should add the route to the application configuration file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.router.routes.sitemap.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Zend_Controller_Router_Route_Static&quot;</span>
resources.router.routes.sitemap.route <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;sitemap.xml&quot;</span>
resources.router.routes.sitemap.defaults.controller <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;sitemap&quot;</span>
resources.router.routes.sitemap.defaults.action <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;redirect&quot;</span></pre></div></div>

<p>We now need to add another action handler to the SitemapController class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> redirectAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/sitemap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The reason for doing this indirect redirection is that if we route directly to <strong>sitemap/index</strong>, the navigator becomes confused and renders all the URLs in the sitemap incorrectly. You can confirm this by changing the ini file setting above from &#8220;redirect&#8221; to &#8220;index&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/adding-an-automatically-generated-sitemap-xml-to-a-zend-framework-site/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A custom resource plugin for populating the registry</title>
		<link>http://zf.gm-ram.com/posts/a-custom-resource-plugin-for-populating-the-registry/</link>
		<comments>http://zf.gm-ram.com/posts/a-custom-resource-plugin-for-populating-the-registry/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 15:21:19 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Bootstrapping]]></category>
		<category><![CDATA[Zend_Application]]></category>
		<category><![CDATA[Zend_Registry]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=686</guid>
		<description><![CDATA[This post looks at a simple custom resource plugin that I&#8217;ve recently created for populating the registry with values from the application configuration file. I have already examined adding a Log plugin and a View plugin in previous posts; the basic technique for adding this one is the same. First we need a line like [...]]]></description>
			<content:encoded><![CDATA[<p>This post looks at a simple custom resource plugin that I&#8217;ve recently created for populating the registry with values from the application configuration file. I have already examined adding a <a href="http://zf.gm-ram.com/posts/bootstrapping-the-application-a-custom-log-resource-plugin/">Log plugin</a> and a <a href="http://zf.gm-ram.com/posts/bootstrapping-the-application-a-custom-view-resource-plugin/">View plugin</a> in previous posts; the basic technique for adding this one is the same.<span id="more-686"></span></p>
<p>First we need a line like this in the configuration file to allow the bootstrapper to find our plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">pluginPaths.Application_Resource <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/resources&quot;</span></pre></div></div>

<p>The key <strong>Application_Resource</strong> indicates the prefix given to the class that implements the plugin, minus its trailing underscore. The value indicates the location in which the plugins with this prefix are stored.</p>
<p>The class itself is implemented in <em>Registry.php</em> in the <em>resources</em> directory. It contains the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Application_Resource_Registry 
  <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_ResourceAbstract
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Get the registry object</span>
    <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get the options that should be placed in the registry</span>
    <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Add the options to the registry</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$index</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code should be fairly self-explanatory. The options are key/value pairs retrieved from the configuration file, e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.registry.phone <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;phone number&quot;</span></pre></div></div>

<p>In the above case, the value <strong>&#8220;phone number&#8221;</strong> is stored under the index <strong>phone</strong> in the registry.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/a-custom-resource-plugin-for-populating-the-registry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Practical Web 2.0 Applications with PHP by Quentin Zervaas</title>
		<link>http://zf.gm-ram.com/posts/practical-web-2-0-applications-with-php-by-quentin-zervaas/</link>
		<comments>http://zf.gm-ram.com/posts/practical-web-2-0-applications-with-php-by-quentin-zervaas/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 18:06:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Book Reviews]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=638</guid>
		<description><![CDATA[Order this book from Amazon Books or articles about PHP or JavaScript have usually been pitched at the novice programmer; this is fine if you are a novice programmer, but as someone with considerable experience of C++ and other such languages, I don&#8217;t fall into that category. As a result, I find these works tend [...]]]></description>
			<content:encoded><![CDATA[<p><div class="amzshcs" id="amzshcs-c2b5bfdd48a72f7780e2d7c268cc0134"><p class="amzshcs-item" id="amzshcs-item-1c723df1ca69ba1c0b8705254e6ac5c6"> <a href="http://www.amazon.co.uk/Practical-Web-Applications-Experts-Voice/dp/1590599063%3FSubscriptionId%3D0Q6PV2EJW475YY8RA6R2%26tag%3Dthezenfrainpr-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1590599063"><img src="http://ecx.images-amazon.com/images/I/41o1KQASzoL._SL75_.jpg" height="75" width="60" alt="Image of Practical Web 2.0 Applications with PHP (Expert's Voice)" title="Practical Web 2.0 Applications with PHP (Expert's Voice)" /> Order this book from Amazon</a> </p></div></p>
<p>Books or articles about PHP or JavaScript have usually been pitched at the novice programmer; this is fine if you are a novice programmer, but as someone with considerable experience of C++ and other such languages, I don&#8217;t fall into that category. As a result, I find these works tend to finish at the point where I&#8217;d like them to begin! For me, the chief merit of <em>Practical Web 2.0 Applications with PHP</em> by Quentin Zervaas is that it is pitched at a higher level, and therefore addresses the sort of topics that I am more interested in.<span id="more-638"></span></p>
<p>The book looks at the development of a complete <em>Web 2.0</em> application. The thing that first drew me to the book was that it used the Zend Framework, which I was in the process of learning at the time. It uses Zend Framework 1.0 in its examples, so there are plenty of modules that have been added to subsequent versions of the framework that the author might have used in his examples, but obviously couldn&#8217;t. Undoubtably the most useful thing I learnt was how to use Zend Controller plugins to perform such tasks as checking whether a user is logged in.</p>
<p>The book somewhat eccentrically uses Smarty for rendering its view scripts rather than the built in Zend Framework mechanism. I have not tried this out in practice, since I am happy enough with the existing facilities, especially following the introduction of modules such as Zend_Layout and Zend_Paginator. However, the examples work fine and may be of interest, either because you have a preference for using Smarty, or because you have some exisiting Smarty templates you wish to reuse within the Zend Framework.</p>
<p>The author includes some of his own classes that he uses to manage database access. These are built on top of the existing Zend Framework databases classes. They represent a decent approach to handling databases read/write operations in a clean fashion.</p>
<p>The JavaScript in the book uses the Prototype/Scriptaculous libraries. The specific usefulness of these examples will be determined by whether you use these libraries, but the general approach to using JavaScript is of wider relevance.</p>
<p>Overall, I found this a very helpful book. There were some things in it that were of direct use, but just as importantly, it was a stimulating look at developing a complex web application from a higher level.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/practical-web-2-0-applications-with-php-by-quentin-zervaas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking that a password is repeated correctly using Zend_Validate_Identical</title>
		<link>http://zf.gm-ram.com/posts/checking-that-a-password-is-repeated-correctly-using-zend_validate_identical/</link>
		<comments>http://zf.gm-ram.com/posts/checking-that-a-password-is-repeated-correctly-using-zend_validate_identical/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 09:41:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Validate]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=664</guid>
		<description><![CDATA[When a user is asked to enter a new password, it is customary to ask the user to repeat it, in order to reduce the risk of it being entered incorrectly. In the Zend Framework, there is a validator that can check whether two items are identical, but using it with Zend_Form is tricky, because [...]]]></description>
			<content:encoded><![CDATA[<p>When a user is asked to enter a new password, it is customary to ask the user to repeat it, in order to reduce the risk of it being entered incorrectly. In the Zend Framework, there is a validator that can check whether two items are identical, but using it with Zend_Form is tricky, because it needs the values of two fields to make the comparison, while validators are attached to a single field, independently of the others. This article looks at how to use Zend_Validate_Identical with Zend_Form.<span id="more-664"></span></p>
<p>Let us assume that we are adding our password and password repeat fields in the <strong>init</strong> method of our form class, which is derived from Zend_Form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'label'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Password:'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'maxLength'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">64</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'required'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'decorators'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFieldDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'errorMessages'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please enter a password'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'repeat_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'label'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Repeat Password:'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'maxLength'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">64</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'required'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'decorators'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFieldDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'errorMessages'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please repeat the password correctly'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that both fields have the <strong>required</strong> option set to true; this is necessary event in the case of the <strong>repeat_password</strong> field, where we will be adding another validator later on. Also note that we have specified custom error messages for both fields, since the default messages are not appropriate.</p>
<p>The second and final step is to override the <strong>isValid</strong> method of the form class, and add the validator there:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'repeat_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
      <span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_Identical<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>It is necessary to do it at this point, since it is only then that we have access to the value of the <strong>password</strong> field.</p>
<p>The form will now fail to validate if the password is not repeated correctly, and the appropriate error message will be generated.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/checking-that-a-password-is-repeated-correctly-using-zend_validate_identical/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pagination using Zend_Paginator</title>
		<link>http://zf.gm-ram.com/posts/pagination-using-zend_paginator/</link>
		<comments>http://zf.gm-ram.com/posts/pagination-using-zend_paginator/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 12:54:51 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_Controller]]></category>
		<category><![CDATA[Zend_Db]]></category>
		<category><![CDATA[Zend_Paginator]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=652</guid>
		<description><![CDATA[Any web application that retrieves large amounts of data for display is bound to have the need to split that data over several pages. Developing the code to do this from scratch is not trivial, so it is extremely useful that the Zend Framework has the Zend_Paginator module, which assists with this task. Zend_Paginator works [...]]]></description>
			<content:encoded><![CDATA[<p>Any web application that retrieves large amounts of data for display is bound to have the need to split that data over several pages. Developing the code to do this from scratch is not trivial, so it is extremely useful that the Zend Framework has the Zend_Paginator module, which assists with this task.<span id="more-652"></span></p>
<p>Zend_Paginator works as follows:</p>
<ol>
<li>The paginator is passed either an actual set of data, or a database query that can be used to retrieve the data.</li>
<li>The paginator will by default retrieve the first page and 10 items on that page; the page and the items per page can be set at this point if necessary.</li>
<li>The paginator can be used to render a navigator, by retrieving the current page and the number of pages.</li>
<li>The paginator can be used to render the current page, by iterating over the paginator to retrieve each item in order.</li>
</ol>
<p>I shall give a concrete example of how this can be implemented below, based on an application I am currently developing.</p>
<p>First, let us start with the controller. In this instance, the controller is <strong>user</strong> and the action is <strong>index</strong>. The skeleton for this code is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Insert implementation here</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The current page will be passed via the URL as a parameter. The first task in the action handler is therefore to retrieve the page number. If it is not specified, it will default to 1.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Get the current page</span>
    <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The next step is to construct a Zend_Db_Select object that represents the database query. To do this we need a database adapter; below, we assume that this has been created during the bootstrapping process and can be retrieved via the bootstrap object. The query simply retrieves all records from the user table, ordering them by the user&#8217;s display name.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Get the boostrap object</span>
    <span style="color: #000088;">$bootstrap</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get the database adapter</span>
    <span style="color: #000088;">$dbAdapter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Create the selection object</span>
    <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbAdapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we have the select object, we can use it to create the paginator object.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Get a Paginator object using Zend_Paginator's built-in factory</span>
    <span style="color: #000088;">$paginator</span> <span style="color: #339933;">=</span> Zend_Paginator<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can then set the number of items per page and the current page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Set the number of items to show per page</span>
    <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setItemCountPerPage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Select the requested page</span>
    <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentPageNumber</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, we should pass the paginator object to the view script.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">;</span></pre></div></div>

<p>The view script used is given below. Note that the application uses Zend_Layout, so only the unique content of the page needs to be generated here.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;h3&gt;User Management&lt;/h3&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Display pagination control</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginationControl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Elastic'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'paginator.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th width=&quot;25%&quot;&gt;Username&lt;/th&gt;
      &lt;th width=&quot;25%&quot;&gt;Role&lt;/th&gt;
      &lt;th width=&quot;50%&quot;&gt;Name&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #666666; font-style: italic;">// Render each item for the current page in a table row</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;tr&gt;
      &lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
      &lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'role'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
      &lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
    &lt;/tr&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;/tbody&gt;
&lt;/table&gt;</pre></div></div>

<p>The script uses the <strong>PaginationControl</strong> view helper to render the navigator. The view script for the navigator markup is specified as one of the parameters as <em>paginator.phtml</em>; this script is found in the <em>/application/views/scripts</em> directory. The following standard script is used:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pageCount</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;paginator&quot;&gt;
&nbsp;
&lt;!-- First page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">previous</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">first</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    First
  &lt;/a&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;First&lt;/span&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!-- Previous page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">previous</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">previous</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    &lt; Previous
  &lt;/a&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;&lt; Previous&lt;/span&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!-- Next page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    Next &gt;
  &lt;/a&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;Next &gt;&lt;/span&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!-- Last page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    Last
  &lt;/a&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;Last&lt;/span&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The section used to render the current page as a table makes use of the fact that the paginator object can be iterated over to retrieve each item on the current page in turn.</p>
<p>The following styling is applied to the navigator:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.paginator</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The following styling is applied to the table:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
th<span style="color: #00AA00;">,</span> td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
th <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#4E7DD1</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/pagination-using-zend_paginator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting Up a Zend Framework Application on IIS</title>
		<link>http://zf.gm-ram.com/posts/setting-up-a-zend-framework-application-on-iis/</link>
		<comments>http://zf.gm-ram.com/posts/setting-up-a-zend-framework-application-on-iis/#comments</comments>
		<pubDate>Sat, 15 May 2010 11:44:20 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=646</guid>
		<description><![CDATA[There are several problems associated with running Zend Framework applications on IIS. This post looks at how to address these problems. The application itself needs to be stored in an appropriate location, such as C:\Websites\mysite. This will contact the application, public and library directories. The public directory may have a different name, such as htdocs, [...]]]></description>
			<content:encoded><![CDATA[<p>There are several problems associated with running Zend Framework applications on IIS. This post looks at how to address these problems.<span id="more-646"></span></p>
<ol>
<li>The application itself needs to be stored in an appropriate location, such as <em>C:\Websites\mysite</em>. This will contact the <em>application</em>, <em>public </em>and <em>library </em>directories. The <em>public</em> directory may have a different name, such as <em>htdocs</em>, depending on the target system.</li>
<li>You need to create a virtual host with the name of the application (e.g. <strong>mysite</strong>), which points at the <em>public </em>directory (e.g. <em>C:\Websites\mysite\public</em>).</li>
<li>The framework works best when used with URL rewriting. There is a standard rewriting module on Apache, called <strong>mod_rewrite</strong>. For a long time there was no such standard extension for IIS. However, Microsoft has developed <a title="IIS URL Rewrite" href="http://www.iis.net/expand/URLRewrite" target="_blank">IIS URL Rewrite</a>, which provides the necessary functionality. To make use of this, you need to download and install the extension from <a title="IIS URL Rewrite" href="http://www.iis.net/expand/URLRewrite" target="_blank">here</a>.</li>
<li>Then you need to add the following <em>web.config</em> file to the <em>public </em>directory:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Imported Rule 1&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;^.*$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions</span> <span style="color: #000066;">logicalGrouping</span>=<span style="color: #ff0000;">&quot;MatchAny&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsFile&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsDirectory&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;None&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Imported Rule 2&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;^.*$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;index.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Finally, you need to set the default document for the directory to <em>index.php</em>.</li>
<li>Because you typically set up a virtual host as a subdirectory of the default website, e.g. http://localhost/mysite, you should make sure that you use the correct base for all the URLs in your application. To that end, you can use the Base URL view helper, which comes with the Zend Framework as standard. For instance, if your contact page is reached via a request for <strong>/contact</strong>, you can make sure that the link is given the correct prefix as follows:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;p&gt;Click &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;here&lt;/a&gt; 
to contact us.&lt;/p&gt;</pre></div></div>

</li>
</ol>
<p>The above should ensure that the application you develop runs in the same way on IIS as it would on Apache.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/setting-up-a-zend-framework-application-on-iis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Blogs Page: The feed digest view helper</title>
		<link>http://zf.gm-ram.com/posts/the-blogs-page-the-feed-digest-view-helper/</link>
		<comments>http://zf.gm-ram.com/posts/the-blogs-page-the-feed-digest-view-helper/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 09:41:38 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[GM-RAM Website]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_Feed]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=598</guid>
		<description><![CDATA[The feed digest helper is used to fetch a list of the most recent items posted on a blog, using its RSS feed. The feed digest class is named Default_View_Helper_FeedDigest and stored in the /application/views/helpers directory in a file called FeedDigest.php. The basic skeleton of the class is as follows: class Default_View_Helper_FeedDigest extends Zend_View_Helper_Abstract &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>The feed digest helper is used to fetch a list of the most recent items posted on a blog, using its RSS feed.<span id="more-598"></span></p>
<p>The feed digest class is named <strong>Default_View_Helper_FeedDigest</strong> and stored in the <em>/application/views/helpers</em> directory in a file called <em>FeedDigest.php</em>.</p>
<p>The basic skeleton of the class is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Default_View_Helper_FeedDigest <span style="color: #000000; font-weight: bold;">extends</span> Zend_View_Helper_Abstract
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> feedDigest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #339933;">,</span> <span style="color: #000088;">$maxItems</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Implementation of view helper</span>
    <span style="color: #339933;">...</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The Zend Framework documentation recommends that the helper either extends the class <strong>Zend_View_Helper_Abstract</strong> or implements the interface <strong>Zend_View_Helper_Interface</strong>. This is to provide support for the <strong>setView</strong> method, which will be called to give the helper automatic access to the view object.</p>
<p>The class returns the HTML that should be used to render the digest. The code that fetches the digest information and turns it into an unordered HTML list is wrapped in a try/catch block; this allows any feed errors to be caught.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    try
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// Fetch feed digest</span>
      <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
    catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// Feed import failed</span>
      <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first step is to perform the feed import, using the URI supplied:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #666666; font-style: italic;">// Import feed</span>
      <span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> Zend_Feed<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The next step is to check the number of elements returned; if there are none, we need to render an appropriate meesage:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #666666; font-style: italic;">// Generate digest of feed</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Render contents of feed</span>
        <span style="color: #339933;">..</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span></pre></div></div>

<p>If there are feed entries, these need to be converted into a list of links, with the appropriate URL and text; the number of entries returned is limited by the $maxItems parameter passed to the helper:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// Add the item to the list</span>
          <span style="color: #000088;">$pubDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d M Y'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;a href=&quot;%s&quot; rel=&quot;nofollow&quot;&gt;%s - %s&lt;/a&gt;'</span><span style="color: #339933;">,</span> 
            <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pubDate</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #666666; font-style: italic;">// Check whether the maximum item limit has been reached</span>
          <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
&nbsp;
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$maxItems</span><span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally the array is rendered as an unordered list:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">htmlList</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Because <strong>Zend_View_Helper_Abstract</strong> supports <strong>setView</strong>, and the helper is derived from that class, it can access other helpers via $this->view.</p>
<p>The second parameter passed to the HtmlList helper (<strong>false</strong>) indicates an unordered list; <strong>true</strong> would indicate an ordered list.</p>
<p>The fourth parameter is set to <strong>false</strong>, to indicate that the text in each array element should not be escaped; this is essential as they contain HTML links that should be rendered verbatim.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/the-blogs-page-the-feed-digest-view-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Blogs Page: The feed/digest view script</title>
		<link>http://zf.gm-ram.com/posts/the-blogs-page-the-feeddigest-view-script/</link>
		<comments>http://zf.gm-ram.com/posts/the-blogs-page-the-feeddigest-view-script/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 23:02:27 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[GM-RAM Website]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=596</guid>
		<description><![CDATA[The view script for the feed/digest action is straightforward. If there is an error, that is rendered; otherwise, the feed digest is displayed. if &#40;isset&#40;$this-&#62;errorMessage&#41;&#41; &#123; if &#40;APPLICATION_ENV == 'development'&#41; &#123; printf&#40;'&#60;p class=&#34;error&#34;&#62;%s&#60;/p&#62;', $this-&#62;errorMessage&#41;; &#125; else &#123; echo '&#60;p&#62;&#60;strong&#62;Recent Posts:&#60;/strong&#62; None found&#60;/p&#62;' . PHP_EOL; &#125; &#125; else &#123; $digest = $this-&#62;feedDigest&#40;$this-&#62;blog-&#62;feed&#41;; &#160; if &#40;strlen&#40;$digest&#41; &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>The view script for the feed/digest action is straightforward. If there is an error, that is rendered; otherwise, the feed digest is displayed.<span id="more-596"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>APPLICATION_ENV <span style="color: #339933;">==</span> <span style="color: #0000ff;">'development'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;error&quot;&gt;%s&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorMessage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Recent Posts:&lt;/strong&gt; None found&lt;/p&gt;'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$digest</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feedDigest</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">blog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Recent Posts:&lt;/strong&gt;&lt;/p&gt;'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$digest</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Recent Posts:&lt;/strong&gt; None found&lt;/p&gt;'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The view helper used to generate the digest will be examined in the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/the-blogs-page-the-feeddigest-view-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
