<?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_Layout</title>
	<atom:link href="http://zf.gm-ram.com/topics/zend_layout/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>Using CKEditor with the Zend Framework</title>
		<link>http://zf.gm-ram.com/posts/using-ckeditor-with-the-zend-framework/</link>
		<comments>http://zf.gm-ram.com/posts/using-ckeditor-with-the-zend-framework/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 16:39:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[ZendX_JQuery]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Layout]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=913</guid>
		<description><![CDATA[At the moment I am working on create a system that allows non-technical users to easily add and edit product pages on one of the website I have developed. Until now, adding or modifying a page has required modifications to the database and/or a PHP script file, along with uploading any new resources, such as [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment I am working on create a system that allows non-technical users to easily add and edit product pages on one of the website I have developed. Until now, adding or modifying a page has required modifications to the database and/or a PHP script file, along with uploading any new resources, such as images or documents. This has meant in practice that either I or one of the more technically minded people at the client has tended to do these changes. The idea of the new system is that it will allow anyone to add/edit product pages.<span id="more-913"></span></p>
<p>Each product page has a standard layout. The page divides into two vertical sections; the top vertical section is divided into two columns. The left column contains the main text describing the products on that page; the right column contains supplementary images and download links. The bottom vertical section contains a jQuery UI tab control, with one tab for each section of products being offered for sale on that page.</p>
<p>I needed to allow the user to edit the HTML used in the top left section. However, I didn&#8217;t want the user to have to write raw HTML, but rather to use a WYSIWYG editor. I identified the Open Source JavaScript editor CKEditor as a suitable candidate.</p>
<p>The process of integrating this editor with the existing Zend Framework application proved to be pretty simple:</p>
<ol>
<li>Download the latest version of the editor from <a href="http://ckeditor.com/" title="CKEditor website">the CKEditor website</a>.</li>
<li>Having unpacked the download, I uploaded the CKEditor directory (<em>ckeditor</em>) under the public web root (<em>htdocs</em>).</li>
<li>The layout script already contained the following in the page head, which forced the appropriate tags to load and enable jQuery to be added:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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;">-&gt;</span><span style="color: #004000;">enable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>I added the following at the top of the view scripts that were going to make use of the editor. Note that the ID of the form field that was going to be enhanced by the editor was <strong>description</strong>.

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// CKEditor</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;">addJavascriptFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/ckeditor/ckeditor.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;">addJavascriptFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/ckeditor/adapters/jquery.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;">addOnload</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;$('#description').ckeditor();&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>I created a class to handle the form that used the editor. The class was named <strong>Application_Form_ProductPage</strong> and ultimately derived from Zend_Form via Application_Form_Abstract.</li>
<li>The init method of the class contained the following code to add the textarea that was enhanced going to be the editor:

<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;">'textarea'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</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;">'Product Description'</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: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ol>
<p>As a result of the able, the textarea was transformed into a fully-blown WYSIWYG editor. The raw HTML was passed behind the scenes, and was added to/retrieved from the database.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/using-ckeditor-with-the-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Lightbox to the GM-RAM Website</title>
		<link>http://zf.gm-ram.com/posts/adding-lightbox-to-the-gm-ram-website/</link>
		<comments>http://zf.gm-ram.com/posts/adding-lightbox-to-the-gm-ram-website/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 11:39:59 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[ZendX_JQuery]]></category>
		<category><![CDATA[Zend_Layout]]></category>
		<category><![CDATA[Zend_View]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=729</guid>
		<description><![CDATA[To quote the Lightbox 2 website: Lightbox is a simple, unobtrusive script used to overlay images on the current page. It&#8217;s a snap to setup and works on all modern browsers. I decided to add the script to the GM-RAM website in order to allow visitors to view full-sized versions of the screen shots there [...]]]></description>
			<content:encoded><![CDATA[<p>To quote the <a href="http://www.huddletogether.com/projects/lightbox2/">Lightbox 2 website</a>:</p>
<blockquote><p>Lightbox is a simple, unobtrusive script used to overlay images on the current page. It&#8217;s a snap to setup and works on all modern browsers.</p></blockquote>
<p>I decided to add the script to the GM-RAM website in order to allow visitors to view full-sized versions of the screen shots there without having to navigate to a separate page.<span id="more-729"></span></p>
<p>I downloaded the Lightbox JavaScript, style sheet and images that need to be placed in the publically-accessible part of the website. The JavaScript files were stored under <em>/js/lightbox/</em>, the style sheet at <em>/css/lightbox.css</em> and the images under <em>/img/lightbox</em>.</p>
<p>The first challenge arose from the fact that the site already uses jQuery, while Lightbox is based on <a href="http://www.prototypejs.org/">Prototype</a> and <a href="http://script.aculo.us/">Scriptaculous</a>. As both use the dollar ($) symbol, it was necessary to put jQuery into no conflict mode. Fortunately, as I was using ZendX_JQuery, there is a built-in mechanism for handling this.</p>
<p>In order to make sure that you use the correct jQuery &#8220;handler&#8221; character ($ or something else), you should dynamically determine what this is. An example of this is from the view handler I wrote to create the JavaScript used to load the results of an AJAX request into a block on the page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Application_View_Helper_LoadScript <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> loadScript<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$jqHandler</span> <span style="color: #339933;">=</span> ZendX_JQuery_View_Helper_JQuery<span style="color: #339933;">::</span><span style="color: #004000;">getJQueryHandler</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$script</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$jqHandler</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'(&quot;#%s&quot;).html(&quot;Loading...&quot;); '</span> <span style="color: #339933;">.</span> 
      <span style="color: #000088;">$jqHandler</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'(&quot;#%s&quot;).load(&quot;%s&quot;);'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</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;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOnload</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$script</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lightbox works unobtrusively by looking for links with the <strong>rel</strong> attribute set to either just <strong>lightbox</strong> or <strong>lightbox[<em>group-name</em>]</strong>, where <em>group-name</em> is set to the same value for a series of images that the user should be able to view by navigating forwards and backwards. The links are wrapped around an image.</p>
<p>I changed the attributes of the images in line with this on the relevant pages. I then created a common script to be included in all the pages, which would set up Lightbox on them. The script is called <em>lightbox.phtml</em> and is located in <em>/application/views/scripts</em>. It is added to the pages&#8217; view scripts by the following line:</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;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lightbox.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The <em>lightbox.phtml</em> script starts by activating jQuery no conflict mode; as noted before, this is because Lightbox uses Prototype and Scriptaculous.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">ZendX_JQuery_View_Helper_JQuery<span style="color: #339933;">::</span><span style="color: #004000;">enableNoConflictMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The script then adds the Lightbox JavaScript files. It is possible to do this here, as the view script is rendered <strong>before</strong> the layout, and therefore when <strong>echo $this->headScript()</strong> is used in the layout script to finally generate the list of script tags in the header, these are included in the output generated.</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;">headScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendFile</span><span style="color: #009900;">&#40;</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;">'/js/lightbox/prototype.js'</span><span style="color: #009900;">&#41;</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;">headScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendFile</span><span style="color: #009900;">&#40;</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;">'/js/lightbox/scriptaculous.js?load=effects,builder'</span><span style="color: #009900;">&#41;</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;">headScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendFile</span><span style="color: #009900;">&#40;</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;">'/js/lightbox/lightbox.js'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Because the implementation of Lightbox assumes locations for its images that are not always correct, we need to add some JavaScript to change them. The script we generate is added using the same mechanism as for the basic script files, although here we are using inline script that we have generated.</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;">headScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendScript</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'LightboxOptions.fileLoadingImage = &quot;'</span> <span style="color: #339933;">.</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;">'/img/lightbox/loading.gif'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;;'</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;">headScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendScript</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'LightboxOptions.fileBottomNavCloseImage = &quot;'</span> <span style="color: #339933;">.</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;">'/img/lightbox/closelabel.gif'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then we add the Lightbox style sheet using a similar mechanism, this time using the <strong>headLink</strong> helper. This helper is called via <strong>echo $this->headLink()</strong> in the layout script, which renders this link along with the others added there.</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;">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: #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;">'/css/lightbox.css'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, we need to override some of the styling, which relates to the location of images. We used the <strong>headStyle</strong> helper for this; as with the <strong>headScript</strong> and <strong>headLink </strong> helpers, this relies on the layout script making a call to the helper, this time via <strong>echo $this->headStyle()</strong>. Note that this call to <strong>headStyle</strong> should come after the call to <strong>headLink</strong> in the header to ensure the overriding of the styling.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">$this-&gt;headStyle()-&gt;captureStart();
?&gt;
#prevLink:hover, #prevLink:visited:hover
{
  background: url(<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;">'/img/lightbox/prevlabel.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>) 
left 15% no-repeat;
}
&nbsp;
#nextLink:hover, #nextLink:visited:hover
{
  background: url(<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;">'/img/lightbox/nextlabel.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>) 
right 15% no-repeat;
}
<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;">headStyle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">captureEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note the use of the <strong>captureStart</strong> and <strong>captureEnd</strong> methods to allow the CSS to be rendered inline.</p>
<p>Regarding the calls to <strong>headScript</strong>, <strong>headLink</strong> and <strong>headStyle</strong>, the relevant section of the layout script is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Scripts</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headScript</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;">prependStylesheet</span><span style="color: #009900;">&#40;</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;">'/css/default.css'</span><span style="color: #009900;">&#41;</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: #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;">'/img/favicon.ico'</span><span style="color: #009900;">&#41;</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>
&nbsp;
<span style="color: #666666; font-style: italic;">// Styles</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headStyle</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></pre></div></div>

<p>Now the Lightbox effect should be applied to all the tagged images on the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/adding-lightbox-to-the-gm-ram-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Contact Page: The Action Handler</title>
		<link>http://zf.gm-ram.com/posts/the-contact-page-the-action-handler/</link>
		<comments>http://zf.gm-ram.com/posts/the-contact-page-the-action-handler/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:35:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Zend_Controller]]></category>
		<category><![CDATA[Zend_Filter]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Layout]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=436</guid>
		<description><![CDATA[The visual implementation of the contact page is similar to that of the home page, as described in the post The Home Page. However, it also makes use of Zend_Form and Zend_Validate to render and process the contact form, and Zend_Layout, Zend_Filter and Zend_Mail to render and send the contact e-mail to the site admin. [...]]]></description>
			<content:encoded><![CDATA[<p>The visual implementation of the contact page is similar to that of the home page, as described in the post <a href="/posts/the-home-page/">The Home Page</a>. However, it also makes use of Zend_Form and Zend_Validate to render and process the contact form, and Zend_Layout, Zend_Filter and Zend_Mail to render and send the contact e-mail to the site admin.<span id="more-436"></span></p>
<p>As the implementation is complex and is spread over a number of files and classes, I shall be looking at it over the course of several posts. In this post I shall be concentrating on the action handler.</p>
<p>The action handler starts by retrieving the request object:</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> contactAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$request</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;">;</span></pre></div></div>

<p>This will be used to determine whether the user has submitted the contact form and what data was submitted.</p>
<p>Then the function creates the form object:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Form_Contact<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We shall look at the implementation of this class in a later post.</p>
<p>Then the function determines whether the user has posted the form:</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: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span></pre></div></div>

<p>If the user has posted the form, the function retrieves the data posted and validates it against the form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><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: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span></pre></div></div>

<p>If the data is valid, the function then creates and sends the e-mail.</p>
<p>The first step is to create a Zend_Layout object, then set the layout script and its location:</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: #000088;">$layout</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Layout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLayoutPath</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/layouts/scripts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact-email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The Zend_Layout will now look for a file called <em>contact-email.phtml</em> in the <em>application/layouts/scripts</em> directory.</p>
<p>The next step is to create a filter and use it to eliminate any possible HTML injection, before passing the parameters to the layout script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$htmlEntities</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Filter_HtmlEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$htmlEntities</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</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: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$htmlEntities</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$htmlEntities</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then the layout is rendered and stored in a variable:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$bodyHtml</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$layout</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></pre></div></div>

<p>The sending of the mail is handled by the Default_Model_Mail_Contact class, which will be examined in a later post. The function creates an object of that class and call its send method, passing the HTML generated above as the parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_Mail_Contact<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bodyHtml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then a variable is passed to the view script to flag that the mail has been sent:</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;">sent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Any exceptions thrown during the process of sending the mail are handled in the following catch block:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      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: #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: #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: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>If the form validation fails, the error is passed in a variable to the view script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <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;">error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFirstFormError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, the form object is always passed to the view script, to allow it to be rendered if necessary.</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The layout script for the e-mail is quite simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div&gt;
  &lt;div&gt;&lt;strong&gt;Name:&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;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
  &lt;div&gt;
    &lt;strong&gt;E-mail:&lt;/strong&gt; 
    &lt;a href=&quot;mailto:<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;">email</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&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;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
  &lt;/div&gt;
  &lt;div&gt;&lt;strong&gt;Message:&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;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>The fields submitted by the user are injected into the appropriate places in the e-mail.</p>
<p>In the next post, I shall look at the view script for the contact page.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/the-contact-page-the-action-handler/feed/</wfw:commentRss>
		<slash:comments>0</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>Zend Framework Layouts Overview</title>
		<link>http://zf.gm-ram.com/posts/zend-framework-layouts-overview/</link>
		<comments>http://zf.gm-ram.com/posts/zend-framework-layouts-overview/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 19:04:28 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Zend_Layout]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=294</guid>
		<description><![CDATA[The Zend Framework is shipped with a template module called Zend_Layout. This allows the specific content for a page to be injected into one or more places in some standard content. The standard content is contained in a layout script, which is much like a view script. The script will contain the following piece of [...]]]></description>
			<content:encoded><![CDATA[<p>The Zend Framework is shipped with a template module called Zend_Layout. This allows the specific content for a page to be injected into one or more places in some standard content.<span id="more-294"></span></p>
<p>The standard content is contained in a layout script, which is much like a view script. The script will contain the following piece of PHP code, or something very like it, to inject the content rendering by the view script into the layout script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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></pre></div></div>

<p>There are several ways to turn on the template engine; one has been covered in the post <a href="/posts/bootstrapping-the-application-the-standard-layout-resource-plugin/">Bootstrapping the Application: the Standard Layout Resource Plugin</a>. Note that the location of the layout scripts is specified in the configuration file settings. It is also possible to set the location directly from the controller, like this:</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;">setLayoutPath</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> 
  <span style="color: #0000ff;">&quot;/layouts/scripts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that the layout is accessed from the controller via the helper broker <strong>$this->_helper</strong>; this object is configured to expose all the available helpers as if they were member variables of that object.</p>
<p>By default, the engine looks for a script called <em>layout.phtml</em>; if you want to use a different script, you need to specify it explicitly. For instance, the application also uses the engine to render the contact e-mail; the name of the script it uses is <em>contact-email.phtml</em>. The following code would instruct the engine to use this 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>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact-email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you want to disable the use of the layout for a particular action, include the following call in its handler:</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>In the next few posts, we shall look at the main layout script for the sample application in more detail.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/zend-framework-layouts-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bootstrapping the Application: the Standard Layout Resource Plugin</title>
		<link>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-layout-resource-plugin/</link>
		<comments>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-layout-resource-plugin/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 14:07:18 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Bootstrapping]]></category>
		<category><![CDATA[Zend_Application]]></category>
		<category><![CDATA[Zend_Layout]]></category>

		<guid isPermaLink="false">http://zf.gm-ram.com/?p=145</guid>
		<description><![CDATA[The Zend Framework offers a template module called Zend_Layout. This is primarily used to render the standard parts of a web page, such as the header, sidebars and footer, and to insert the variable content into placeholders. However, it can also be used to render other things with standard layouts, such as e-mails. We shall [...]]]></description>
			<content:encoded><![CDATA[<p>The Zend Framework offers a template module called Zend_Layout. This is primarily used to render the standard parts of a web page, such as the header, sidebars and footer, and to insert the variable content into placeholders. However, it can also be used to render other things with standard layouts, such as e-mails. We shall have a look at examples of both in later posts.<span id="more-145"></span></p>
<p>To use Zend_Layout, you need to specify the location of the layout scripts, then invoke Zend_Layout::startMvc(). The standard resource plugin <strong>Zend_Application_Resource_Layout</strong> is used by Zend_Application to automate this process. To use this plugin, you should add the following line to the configuration file:</p>

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

<p>This specifies the location of the layout scripts. If your scripts are in a different location, you should change the value of layoutPath.</p>
<p>We shall look at Zend_Layout in more detail in later posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://zf.gm-ram.com/posts/bootstrapping-the-application-the-standard-layout-resource-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

