<?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 &#187; Zend_Navigation</title>
	<atom:link href="http://zf.gm-ram.com/topics/zend_navigation/feed/" rel="self" type="application/rss+xml" />
	<link>http://zf.gm-ram.com</link>
	<description>Developing Web Applications with the Zend Framework</description>
	<lastBuildDate>Mon, 02 Jan 2012 10:20:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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[Zend_Navigation]]></category>
		<category><![CDATA[Zend_Paginator]]></category>
		<category><![CDATA[Zend_Registry]]></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[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>2</slash:comments>
		</item>
		<item>
		<title>The Navigation Link View Helper</title>
		<link>http://zf.gm-ram.com/posts/the-navigation-link-view-helper/</link>
		<comments>http://zf.gm-ram.com/posts/the-navigation-link-view-helper/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 22:24:57 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Zend_Navigation]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=418</guid>
		<description><![CDATA[In this post we will look at a custom view helper, which is used on the sample website to render a link to a page in the site navigation. The Zend_Navigation module allows us to build up a collection of objects that represent the pages on the site. These pages can then be rendered in [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we will look at a custom view helper, which is used on the sample website to render a link to a page in the site navigation.<span id="more-418"></span></p>
<p>The <strong>Zend_Navigation</strong> module allows us to build up a collection of objects that represent the pages on the site. These pages can then be rendered in different ways, such as a menu or a sitemap.</p>
<p>The helper covered in this post makes use of the Zend_Navigation object that was initialised in the bootstrapping process, as described in the post <a href="/topics/zend_navigation/">Bootstrapping the Application: the Standard Navigation Resource Plugin</a>. Each page added to the navigation was given a unique ID. The helper takes this unique ID, along with some text for the link, and it uses the ID to retrieve the URL of the page from the navigation container object. This allows the exact URL of a page to be stored in just one place, so that it can be changed easily if necessary.</p>
<p>The helper is called Default_View_Helper_NavLink; the prefix Default_View_Helper was specified in the bootstrapping process, as described in the post <a href="/posts/bootstrapping-the-application-a-custom-view-resource-plugin/">Bootstrapping the Application: a Custom View Resource Plugin</a>.</p>
<p>The helper class is stored in a file called <em>NavLink.php</em>, which is in the <em>views/helpers</em> directory.</p>
<p>Here is the code used to implement the class:</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> Default_View_Helper_NavLink <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> navLink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pageId</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Get navigation container</span>
    <span style="color: #000088;">$container</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;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContainer</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 page</span>
    <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneBy</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pageId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If the page is found, generate a link </span>
    <span style="color: #666666; font-style: italic;">// with the specified label text</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;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$html</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;&gt;%s&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// Otherwise just return the label text </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: #000088;">$label</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>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The class contains a method with a name corresponding to the basic helper name, which is essentially the class name but without the prefix. This corresponds to the name of the method used to invoke the helper from the view script.</p>
<p>Note that when a Zend_Navigation object has been set up via a resource plugin, it is automatically available from the view object via the call:</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;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>This object reference is used to retrieve the page container, which can then be searched for the relevant page. This is then used to generate the link.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/the-navigation-link-view-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Sample Application Layout</title>
		<link>http://zf.gm-ram.com/posts/the-sample-application-layout/</link>
		<comments>http://zf.gm-ram.com/posts/the-sample-application-layout/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 13:52:16 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[ZendX_JQuery]]></category>
		<category><![CDATA[Zend_Layout]]></category>
		<category><![CDATA[Zend_Navigation]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=303</guid>
		<description><![CDATA[We looked at Zend_Layout in general terms in the previous now; now we are going to examine the main layout script used in the sample application. The script begins by rendering the DOCTYPE at the head of the page: &#60;?php echo $this-&#62;doctype&#40;&#41; . PHP_EOL; ?&#62; This has previously been set by the custom view resource [...]]]></description>
			<content:encoded><![CDATA[<p>We looked at Zend_Layout in general terms in the previous now; now we are going to examine the main layout script used in the sample application.<span id="more-303"></span></p>
<p>The script begins by rendering the DOCTYPE at the head of the page:</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;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">doctype</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This has previously been set by the custom view resource plugin, as described in the previous post <a href="/posts/bootstrapping-the-application-a-custom-view-resource-plugin/">Bootstrapping the Application: a Custom View Resource Plugin</a>.</p>
<p>The rest of the page is enclosed inside an <strong>html</strong> block:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/1999/xhtml&quot;</span> 
  <span style="color: #990000;">dir</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ltr&quot;</span> lang<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;en&quot;</span> xml<span style="color: #339933;">:</span>lang<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> Page content is rendered here <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The html tag has the following attributes set:</p>
<ul>
<li><strong>xmlns</strong>: This specifies the namespace to use; it is required, as the DOCTYPE is set to XHTML, and it is set to the standard value <a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>.</li>
<li><strong>dir</strong>: This specifies the text direction for the content. It is set to <strong>ltr</strong> (left to right), which is the correct value for English.</li>
<li><strong>lang</strong>: This specifies a language code for the content. It is set to <strong>en</strong> (English).</li>
<li><strong>xml:lang</strong>: This specifies a language code for the content in XHTML documents. It is set to <strong>en</strong> (English).</li>
</ul>
<p>Inside the html block are the <strong>head</strong> and <strong>body</strong> blocks:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> Head content is rendered here <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> Body content is rendered here <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The head block is generated programmatically using Zend Framework view helpers:</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: #666666; font-style: italic;">// Title</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GM-RAM Limited'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Metadata</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headMeta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendHttpEquiv</span>
  <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text/html; charset=UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headMeta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendHttpEquiv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Language'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'en-GB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headMeta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'copyright'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Copyright '</span> <span style="color: #339933;">.</span> 
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'copyrightDate'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GM-RAM Limited'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headMeta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'verify-v1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// Google verification code</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headMeta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// jQuery</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/js/jquery-1.3.2.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUiLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/js/jquery-ui-1.7.2.custom.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addStylesheet</span>
  <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/css/smoothness/jquery-ui-1.7.2.custom.css'</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;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Links</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendStylesheet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/css/default.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headLink</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rel'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'shortcut icon'</span><span style="color: #339933;">,</span> 
  <span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/img/favicon.ico'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'image/x-icon'</span><span style="color: #009900;">&#41;</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;">headLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The view helpers used are:</p>
<ul>
<li><strong>Zend_View_Helper_HeadTitle</strong> (headTitle)</li>
<li><strong>Zend_View_Helper_HeadMeta</strong> (headMeta)</li>
<li><strong>Zend_View_Helper_HeadLink</strong> (headLink)</li>
<li><strong>ZendX_JQuery_View_Helper_JQuery</strong> (jQuery)</li>
</ul>
<p>These all employ the same pattern of usage: one or more calls are made to the relevant function, which aggregates the content to be rendered; each call returns the content so far, but only the last call is actually echoed to the page.</p>
<p>The above code should be fairly self-explanatory in terms of what is being rendered. The call to <strong>headTitle</strong> is used to generate the <strong>title</strong> element; the calls to <strong>headMeta</strong> are used to generate the various metadata elements; the calls to <strong>headLink</strong> are used to add the links to the stylesheet and shortcut icon. As the site makes use of the <strong>jQuery</strong> JavaScript library, there are calls to the jQuery view helper to generate the appropriate elements for including the necessary JavaScript files and also generating the code which sets jQuery to perform certain actions on start up; the latter will be covered in more detail in later posts.</p>
<p>The skeleton structure of the body section is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;wrapper&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> <span style="color: #990000;">Header</span> content is rendered here <span style="color: #339933;">--&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> Main page content is rendered here <span style="color: #339933;">--&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;footer&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> Footer content is rendered here <span style="color: #339933;">--&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The header breaks down into:</p>
<ul>
<li>The navigation menu at the top</li>
<li>The company&#8217;s logo</li>
<li>The description of the company&#8217;s area of business</li>
<li>The company&#8217;s phone number</li>
</ul>
<p>The navigation menu is rendered like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  &lt;div id=&quot;nav&quot;&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;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">menu</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;/div&gt;</pre></div></div>

<p>This uses the Zend_Navigation object, which is initialised using the configuration file as described in the post <a href="/posts/bootstrapping-the-application-the-standard-navigation-resource-plugin/">Bootstrapping the Application: the Standard Navigation Resource Plugin</a>. Here, the pages in the navigation are rendered as a menu, which generates an unordered list of links.</p>
<p>The other three elements are rendered as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  &lt;img src=&quot;/img/logo.gif&quot; alt=&quot;GM-RAM Limited&quot; title=&quot;GM-RAM Limited&quot; /&gt;
  &lt;div&gt;Software Development and Consultancy&lt;/div&gt;
  &lt;div&gt;
    &lt;strong&gt;Phone:&lt;/strong&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;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'phoneNumber'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;/div&gt;</pre></div></div>

<p>Note the use of the placeholder view helper. This makes use of the placeholders set up using a custom resource plugin, as described in the post <a href="/posts/bootstrapping-the-application-a-custom-view-resource-plugin/">Bootstrapping the Application: a Custom View Resource Plugin</a>.</p>
<p>The main page content simply consists of a call to fetch the layout object, so that its content member variable can be rendered:</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;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This results in the output generated by the view script for the specific page being injected into the content div.</p>
<p>The footer consists of the following markup:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div&gt;
  &lt;a href=&quot;http://framework.zend.com/&quot;&gt;
    &lt;img src=&quot;/img/PoweredBy_ZF_4LightBG.png&quot; alt=&quot;Zend Framework&quot; /&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;div&gt;
  Copyright &amp;copy; <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;">placeholder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'copyrightDate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> 
  GM-RAM Limited
&lt;/div&gt;</pre></div></div>

<p>Note again the use of the placeholder view helper.</p>
<p>In the next post, I shall look at the stylesheet for the website, in particular how it applies to the layout script.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/the-sample-application-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bootstrapping the Application: the Standard Navigation Resource Plugin</title>
		<link>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-navigation-resource-plugin/</link>
		<comments>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-navigation-resource-plugin/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 14:10:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Bootstrapping]]></category>
		<category><![CDATA[Zend_Application]]></category>
		<category><![CDATA[Zend_Navigation]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=159</guid>
		<description><![CDATA[Zend_Navigation is a Zend Framework component used to represent the pages on a web site and transform this into things such as page navigation and Google sitemaps. The standard navigation resource plugin Zend_Application_Resource_Navigation can be used to configure an instance of Zend_Navigation. In the sample application, each of the site pages is added via a [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Navigation is a Zend Framework component used to represent the pages on a web site and transform this into things such as page navigation and Google sitemaps. The standard navigation resource plugin <strong>Zend_Application_Resource_Navigation</strong> can be used to configure an instance of Zend_Navigation.<span id="more-159"></span></p>
<p>In the sample application, each of the site pages is added via a block of settings in the configuration file, which take the following form:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.navigation.pages.home.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Zend_Navigation_Page_Mvc&quot;</span>
resources.navigation.pages.home.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Home&quot;</span>
resources.navigation.pages.home.id <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;home_page&quot;</span>
resources.navigation.pages.home.controller <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;index&quot;</span>
resources.navigation.pages.home.action <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;index&quot;</span></pre></div></div>

<p>The sub-element after <strong>pages</strong> (here <strong>home</strong>) is set to a unique name for the page. The purpose of all the settings for this element are as follows:</p>
<ul>
<li><strong>type</strong>: This inidicates how the page location is represented. It is either Zend_Navigation_Page_Mvc, when the module/controller/action associated with the page is specified, or Zend_Navigation_Page_Uri, when a straightforward URI for the page is given.</li>
<li><strong>label</strong>: This is the string used when rendering the page name.</li>
<li><strong>id</strong>: This is the unique ID used to identify the page.</li>
<li><strong>controller</strong>: This is the controller associated with the page (see type above).</li>
<li><strong>action</strong>: This is the action associated with the page (see type above).</li>
</ul>
<p>All the pages are of the type Zend_Navigation_Page_Mvc; the other settings are as follows:</p>
<ul>
<li><strong>home</strong>: Home, home_page, index, index</li>
<li><strong>about</strong>: About Us, about_page, index, about</li>
<li><strong>contact</strong>: Contact Us, contact_page, index, contact</li>
<li><strong>blogs</strong>: Our Blogs, blogs_page, index, blogs</li>
</ul>
<p>Zend_Application_Resource_Navigation will create a container object. It will then populate it with page objects based on the settings in the configuration file.</p>
<p>We will look at how the Zend_Navigation object is used in rendering the page navigation and sitemap in later posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-navigation-resource-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

