<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<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/"
	>

<channel>
	<title>eKini: Web Developer Blog</title>
	<link>http://blog.ekini.net</link>
	<description>PHP, MySQL, Javascript, MVC, Zend Framework, AJAX, jQuery</description>
	<pubDate>Mon, 22 Jun 2009 06:19:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Zend Framework: How to use Zend_Paginator</title>
		<link>http://blog.ekini.net/2009/06/22/zend-framework-how-to-use-zend_paginator/</link>
		<comments>http://blog.ekini.net/2009/06/22/zend-framework-how-to-use-zend_paginator/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:06:05 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[pagination]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[Zend_paginator]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/2009/06/22/zend-framework-how-to-use-zend_paginator/</guid>
		<description><![CDATA[Having a &#8220;search&#8221; functionality in your web application is very essential and for every search comes a &#8220;search results&#8221; page. It is not hard to create your own search results page with a pagination, but it does take a certain amount of time. But by using Zend_Paginator, you will be able to save time and [...]]]></description>
			<content:encoded><![CDATA[<p>Having a &#8220;search&#8221; functionality in your web application is very essential and for every search comes a &#8220;search results&#8221; page. It is not hard to create your own search results page with a pagination, but it does take a certain amount of time. But by using Zend_Paginator, you will be able to save time and make your code easier to understand and debug.</p>
<p>Here is a short example on how to create your own search results page with Zend_Paginator.</p>
<p>Before anything else, we start with our <b>search form</b>.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form method=&quot;GET&quot; action=&quot;&lt;?=$this-&gt;baseUrl()?&gt;/search&quot;&gt;
    SEARCH:
    &lt;input name=&quot;keyword&quot; type=&quot;text&quot;/&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>Next, we have our Controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SearchController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff; font-style: italic;">/**
         * Load model and perform search if $keyword is found in the URL
         */</span>
        <span style="color: #000088;">$content_model</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_Content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="">'keyword'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$content_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchSearchResults</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="">'keyword'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #0000ff; font-style: italic;">/**
         * Setup the paginator if $results is set.
         */</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;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$paginator</span> <span style="color: #339933;">=</span> Zend_Paginator<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setItemCountPerPage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentPageNumber</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="">'page'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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;">paginator</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paginator</span>;
            <span style="color: #0000ff; font-style: italic;">/**
             * We will be using $this-&gt;view-&gt;paginator to loop thru in our view ;-)
             */</span>
&nbsp;
            Zend_Paginator<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultScrollingStyle</span><span style="color: #009900;">&#40;</span><span style="">'Sliding'</span><span style="color: #009900;">&#41;</span>;
            Zend_View_Helper_PaginationControl<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultViewPartial</span><span style="color: #009900;">&#40;</span>
                <span style="">'query/pagination.phtml'</span> <span style="color: #666666; font-style: italic;">//Take note of this, we will be creating this file</span>
            <span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p><i>Note: In this tutorial we are using LIKE to compare strings in our MySQL database. The search is very basic and there is no ranking in our results.</i><br />
<br/><br />
<b>The Model</b><br />
Our model will have 2 files. See below:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff; font-style: italic;">/**
 * First model file.
 * application/models/Content.php
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Default_Model_Content <span style="color: #000000; font-weight: bold;">extends</span> Zend_Db_Table
<span style="color: #009900;">&#123;</span>
    protected <span style="color: #000088;">$_table</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_table<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_table <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_table;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchSearchResults<span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyword</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchSearchResults</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyword</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span>;
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>And our second model file.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff; font-style: italic;">/**
 * Second model file.
 * application/models/DbTable/Content.php
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Default_Model_DbTable_Orders <span style="color: #000000; font-weight: bold;">extends</span> Zend_Db_Table_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff; font-style: italic;">/** Table name */</span>
    protected <span style="color: #000088;">$_name</span> <span style="color: #339933;">=</span> <span style="">'content'</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFetchMode</span><span style="color: #009900;">&#40;</span>Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_OBJ</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchSearchResults<span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyword</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="">'SELECT * FROM'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<span style="color: #339933;">.</span>
                <span style="">'WHERE '</span><span style="color: #339933;">.</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">quoteIdentifier</span><span style="color: #009900;">&#40;</span><span style="">'the_content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">' '</span><span style="color: #339933;">.</span>
                <span style="">'LIKE'</span><span style="color: #339933;">.</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyword</span><span style="color: #339933;">.</span><span style="">'%'</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p><br/><br />
<b>The View</b><br />
Now that we have our controller and model ready, it is time to setup our view files.</p>
<p>First, create a file called <b>index.phtml</b> in <b>application/views/scripts/search/</b>:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;table&gt;
        &lt;tr&gt;
            &lt;th&gt;Title&lt;/th&gt;
            &lt;th&gt;Content&lt;/th&gt;
        &lt;/tr&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;tr&gt;
                &lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span>?<span style="color: #339933;">&gt;</span>&lt;/td&gt;
                &lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_content</span>?<span style="color: #339933;">&gt;</span>&lt;/td&gt;
            &lt;/tr&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/table&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
No results.
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><br/><br />
<b>The Pagination View File</b><br />
This is the last step. Now all you have to do is to copy-paste this section of code into a file named: <b>pagination.phtml</b><br />
Create that file in: <b>application/views/scripts/search/pagination.phtml</b></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;!--
See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
--&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pageCount</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;paginationControl&quot;&gt;
&lt;!-- Previous page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">previous</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">previous</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    &amp;lt; Previous
  &lt;/a&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;&amp;lt; Previous&lt;/span&gt; |
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!-- Numbered page links --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pagesInRange</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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: #990000;">echo</span> <span style="color: #000088;">$page</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/a&gt; |
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;span id=&quot;current_page&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$page</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt; |
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!-- Next page link --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    Next &amp;gt;
  &lt;/a&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;span class=&quot;disabled&quot;&gt;Next &amp;gt;&lt;/span&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Test your search form!</p>
<p><b>More Reading</b><br />
<a href="http://framework.zend.com/manual/en/zend.paginator.usage.html">Zend_Paginator</a> from the Zend.com manual.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2009/06/22/zend-framework-how-to-use-zend_paginator/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On using a CSS Framework - BlueprintCSS</title>
		<link>http://blog.ekini.net/2009/06/21/on-using-a-css-framework-blueprintcss/</link>
		<comments>http://blog.ekini.net/2009/06/21/on-using-a-css-framework-blueprintcss/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 03:24:46 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[blueprint]]></category>

		<category><![CDATA[blueprintcss]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[css framework]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/2009/06/21/on-using-a-css-framework-blueprintcss/</guid>
		<description><![CDATA[A quick background check on BlueprintCSS:

A CSS reset that eliminates the discrepancies across browsers.
A solid grid that can support the most complex of layouts.
Typography based on expert principles that predate the web.
Form styles for great looking user interfaces.
Print styles for making any webpage ready for paper.
Plugins for buttons, tabs and sprites.
Tools, editors, and templates for [...]]]></description>
			<content:encoded><![CDATA[<p>A quick background check on <a href="http://www.blueprintcss.org/">BlueprintCSS</a>:</p>
<ul>
<li>A CSS reset that eliminates the discrepancies across browsers.</li>
<li>A solid grid that can support the most complex of layouts.</li>
<li>Typography based on expert principles that predate the web.</li>
<li>Form styles for great looking user interfaces.</li>
<li>Print styles for making any webpage ready for paper.</li>
<li>Plugins for buttons, tabs and sprites.</li>
<li>Tools, editors, and templates for every step in your workflow.</li>
</ul>
<p>I have heard of Blueprint CSS a couple of months ago. But I have never used it until a few weeks ago because I kept thinking:</p>
<blockquote><p>&#8220;Who needs a CSS Framework? We already have frameworks for Javascript and PHP. And now we have one for CSS? Oh nos.&#8221;</p></blockquote>
<p>The only thing I regret is not using it using it earlier. Read that line again: <em>The only thing I regret is not using it earlier.</em> I cannot stress enough how much time and effort I have saved when I used BlueprintCSS. It just works and it is so damn easy to understand. BlueprintCSS uses a grid-style layout, just like old HTML tables do. </p>
<p><strong>A Quick Overview After a Small Project Using Blueprint</strong></p>
<p>With BlueprintCSS, everything started with a div that is 950px wide. The 950px div can be made up of up to 24 columns. I forgot the width of each column and you can probably find that <a href="http://wiki.github.com/joshuaclayton/blueprint-css/quick-start-tutorial">here</a> but the logic is that you can specify up to 24 columns in your layout. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;span-24&quot;&gt;
        Header - 24 columns and the width is 950px
    &lt;/div&gt;
    &lt;div class=&quot;span-4&quot;&gt;
        Left sidebar - 4 columns
    &lt;/div&gt;
    &lt;div class=&quot;span-20&quot;&gt;
        Content pane - 20 columns
    &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Note that the Left Sidebar (span-4) and the Content Pane (span-20) adds up to 24? That is the basic concept of Blueprint. You can have as many columns as you want as long as it totals to 24. You can also do other useful stuff:</p>
<blockquote><p>Grid.css can do a lot more than this, however. You can prepend and append empty columns, pull or push images across columns, add borders between columns, and use multiple containers to create almost any layout.</p></blockquote>
<p>Using this simple concept, you can basically get any design/layout you have made in Photoshop and quickly make a cross-browser compatible CSS in less than 30 minutes.</p>
<p>All that by simply including a bunch of CSS files.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/blueprint/screen.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;css/blueprint/print.css&quot; type=&quot;text/css&quot; media=&quot;print&quot;&gt;    
&lt;!--[if lt IE 8]&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;css/blueprint/ie.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot;&gt;&lt;![endif]--&gt;</pre></div></div>

<p>A quick and comprehensive tutorial on BlueprintCSS can be found <a href="http://wiki.github.com/joshuaclayton/blueprint-css/quick-start-tutorial">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2009/06/21/on-using-a-css-framework-blueprintcss/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zend Framework: SQL Injection Prevention from DPC Slides</title>
		<link>http://blog.ekini.net/2009/06/17/zend-framework-sql-injection-prevention-from-dpc-zend-framework-slides/</link>
		<comments>http://blog.ekini.net/2009/06/17/zend-framework-sql-injection-prevention-from-dpc-zend-framework-slides/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 06:37:58 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[dpc slides]]></category>

		<category><![CDATA[escaping]]></category>

		<category><![CDATA[sql injection]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[Zend_Db]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/2009/06/17/zend-framework-sql-injection-prevention-from-dpc-zend-framework-slides/</guid>
		<description><![CDATA[I would never make it to any PHP Conference, so I would have to be satisfied by the replays and slides. I got these  from the DPC slides found here (pdf).

function query&#40;$sql, $bind = array&#40;&#41;&#41;

- uses prepared statement internally
- SQL Injection still possible if $sql is dynamically created

function fetchAll&#40;$sql, $bind = array&#40;&#41;, $fetchMode = [...]]]></description>
			<content:encoded><![CDATA[<p>I would never make it to any PHP Conference, so I would have to be satisfied by the replays and slides. I got these  from the DPC slides found <a href="http://www.suspekt.org/downloads/DPC_Secure_Programming_With_The_Zend_Framework.pdf">here</a> (pdf).</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- uses prepared statement internally<br />
- SQL Injection still possible if $sql is dynamically created</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fetchAll<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fetchMode</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- all &#8220;fetch&#8221; methods use prepared statements internally<br />
- SQL Injection still possible if $sql is dynamically created</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT id FROM users WHERE lastname=? AND age=?&quot;</span>;
<span style="color: #000088;">$parans</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'Smith'</span><span style="color: #339933;">,</span><span style="">'18'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>More stufff&#8230;</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> insert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$bind</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- internally uses prepared statements<br />
- SQL-Injection not possible</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$bind</span><span style="color: #339933;">,</span> <span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="">''</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- uses partially prepared statements<br />
- SQL-Injection still possible if $where is dynamically created</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="">''</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- SQL-Injection still possible if $where is dynamically created</p>
<p><strong>Zend_Db - Escaping</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> quote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- applies the correct escaping - one function not many<br />
- ATTENTION: also puts strings in quotes<br />
Note: If the type of your field in your database is an Integer, then I would suggest that you use a second parameter &#8212; see below.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="">'1234'</span>;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="">'SELECT * FROM atable WHERE intColumn = '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="">'INTEGER'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p><br/></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> quoteIdentifier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ident</span><span style="color: #339933;">,</span> <span style="color: #000088;">$auto</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>- applies escaping for identifiers<br />
- a function not available to traditional PHP applications<br />
- ATTENTION: also puts strings in quotes<br />
- Used for table names, columns, and other identifiers in SQL statements</p>
<blockquote><p>
If you use PHP variables to name tables, columns, or other identifiers in your SQL statements, you might need to quote these strings too.
</p></blockquote>
<p><strong>Example:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Default_Model_DbTable_Ordertype <span style="color: #000000; font-weight: bold;">extends</span> Zend_Db_Table_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff; font-style: italic;">/** Table name */</span>
    protected <span style="color: #000088;">$_name</span> <span style="color: #339933;">=</span> <span style="">'order_type'</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFetchMode</span><span style="color: #009900;">&#40;</span>Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_OBJ</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAll<span style="color: #009900;">&#40;</span><span style="color: #000088;">$country_id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="">'SELECT *
                FROM
                '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<span style="color: #339933;">.</span><span style="">'
                WHERE order_type_status = &quot;on&quot;
                AND country_id = ?'</span>;
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$country_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAllQuoted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$country_id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff; font-style: italic;">/**
         * This would also work.
         * But I prefer the one above.
         * It is shorter and easier to read.
         * Both will have the same results.
         */</span>
        <span style="color: #000088;">$country_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$country_id</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="">'SELECT *
                FROM
                '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<span style="color: #339933;">.</span><span style="">'
                WHERE order_type_status = &quot;on&quot;
                AND country_id = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$country_id</span>;
&nbsp;
        <span style="color: #0000ff; font-style: italic;">/**
         * No second parameter.
         */</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2009/06/17/zend-framework-sql-injection-prevention-from-dpc-zend-framework-slides/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Arrogance is Limiting Framework Adoption by Cal Evans</title>
		<link>http://blog.ekini.net/2009/06/16/arrogance-is-limiting-framework-adoption-by-cal-evans/</link>
		<comments>http://blog.ekini.net/2009/06/16/arrogance-is-limiting-framework-adoption-by-cal-evans/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 03:25:17 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[cal evans]]></category>

		<category><![CDATA[frameworks]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/2009/06/16/arrogance-is-limiting-framework-adoption-by-cal-evans/</guid>
		<description><![CDATA[I rarely post articles like these. But this one will hit a spot on some developers. I personally think that arrogance is a dangerous trait for a programmer/developer. I would not want to work with someone who thinks so highly of themselves. If I was to hire a guy for a team; between an inexperienced [...]]]></description>
			<content:encoded><![CDATA[<p>I rarely post articles like these. But this one will hit a spot on some developers. I personally think that arrogance is a dangerous trait for a programmer/developer. I would not want to work with someone who thinks so highly of themselves. If I was to hire a guy for a team; between an inexperienced developer and a guy who claims he has 999 years of experience and thinks that he is Galactus of PHP, then I would pick the first one. </p>
<p><a href="http://www.phparch.com/c/news/view/10/Opinion__Arrogance_is_Limiting_Framework_Adoption">Here is the article</a> from Cal Evans.</p>
<blockquote><p>Developers are notoriously self-confident in their ability to write code that is better, faster, cleaner and better-smelling than everybody else&#8217;s. In today&#8217;s environment, however, the focus is on producing immediately useful code—and, given the richness of today&#8217;s frameworks, those who eschew them in favour of home-grown solutions are forever running the risk of reinventing the wheel for no good reason. We have enough wheels—start building some cars. </p></blockquote>
<blockquote><p> “…Frameworks! I don&#8217;t need no stickin&#8217; PHP Frameworks!!!” – anonymous twitterer</p></blockquote>
<p>It is a good read.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2009/06/16/arrogance-is-limiting-framework-adoption-by-cal-evans/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zend Framework: Navigation and Breadcrumbs with an XML File in ZF 1.8</title>
		<link>http://blog.ekini.net/2009/06/10/zend-framework-navigation-and-breadcrumbs-with-an-xml-file-in-zf-18/</link>
		<comments>http://blog.ekini.net/2009/06/10/zend-framework-navigation-and-breadcrumbs-with-an-xml-file-in-zf-18/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 06:06:39 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[]]></category>

		<category><![CDATA[breadcrumbs]]></category>

		<category><![CDATA[menu]]></category>

		<category><![CDATA[navigation]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[Zend_Navigation]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/2009/06/10/zend-framework-navigation-and-breadcrumbs-with-an-xml-file-in-zf-18/</guid>
		<description><![CDATA[This is related to the Making the Built-in Breadcrumb Helper Work I posted earlier. Thanks to Jonathan Lebensold&#8217;s screencast, I am able to create my navigation and breadcrumbs in a better way. Using an XML file makes more sense than using an array. It is easier to maintain and edit.
What the Navigation will look like:

//layout.phtml
echo [...]]]></description>
			<content:encoded><![CDATA[<p>This is related to the <a href="http://blog.ekini.net/2009/05/25/zend-framework-making-the-built-in-breadcrumb-helper-work/">Making the Built-in Breadcrumb Helper Work</a> I posted earlier. Thanks to <a href="http://www.zendcasts.com/zend_navigation-dynamically-creating-a-menu-a-sitemap-and-breadcrumbs/2009/06/">Jonathan Lebensold&#8217;s screencast</a>, I am able to create my navigation and breadcrumbs in a better way. Using an XML file makes more sense than using an array. It is easier to maintain and edit.</p>
<p><strong>What the Navigation will look like:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//layout.phtml</span>
<span style="color: #990000;">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>;</pre></div></div>

<ul>
<li>
    Home
</li>
<li>
    Query</p>
<ul>
<li>
            My Drafts
        </li>
<li>
            My Orders
        </li>
<li>
            All Open Orders
        </li>
</ul>
</li>
<li>
    Reports</p>
<ul>
<li>
            Country
        </li>
<li>
            Country Revenue
        </li>
</ul>
</li>
</ul>
<p><strong>And what the breadcrumbs will look like:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//layout.phtml</span>
<span style="color: #990000;">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;">breadcrumbs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLinkLast</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMinDepth</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</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>;</pre></div></div>

<ul>
<li>
    You are in: Home
</li>
<li>
    Home > Query</p>
<ul>
<li>You are in: Home > Query > My Drafts</li>
<li>You are in: Home > Query > My Orders</li>
<li>You are in: Home > Query > All Open Orders</li>
</ul>
</li>
<li>
    You are in: Home > Reports</p>
<ul>
<li>You are in: Home > Reports > Country
        </li>
<li>You are in: Home > Reports > Country Revenue</li>
</ul>
</li>
</ul>
<p>To do this, you first create an XML file. It makes more sense to create your XML file inside the <strong>configs </strong>directory. So create an XML file in:</p>
<pre>
application/configs/navigation.xml
</pre>
<p>The data in the XML file should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configdata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nav<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Home<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>dashboard<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Query<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>query<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mydrafts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Drafts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>query<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mydrafts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mydrafts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;myorders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Orders<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>query<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>myorders<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/myorders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allopenorders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>All Open Orders<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>query<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>allopenorders<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/queryname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/allopenorders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reports<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Reports<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>report<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Country<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>report<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>country<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;countryrevenue<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Country Revenue<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>report<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>countryrevenue<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/countryrevenue<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reports<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nav<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configdata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The next part involves editing the Bootstrap.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//add this in your bootstrap file</span>
<span style="color: #666666; font-style: italic;">//application/Bootstrap.php</span>
protected <span style="color: #000000; font-weight: bold;">function</span> _initNavigation<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><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="">'layout'</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$layout</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="">'layout'</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Xml<span style="color: #009900;">&#40;</span>APPLICATION_PATH<span style="color: #339933;">.</span><span style="">'/configs/navigation.xml'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #000088;">$navigation</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Navigation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">navigation</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navigation</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What we are doing here is that we are simply loading the XML file (as an array) into the $view object. We are doing this so that we can access the Zend_Navigation object in our layout/views.</p>
<p><strong>Final Steps</strong><br />
Lastly, you will need to open up your layout file and add these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;menu&quot;&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">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: #000000; font-weight: bold;">?&gt;</span>
        &lt;/div&gt;
        &lt;div id=&quot;breadcrumbs&quot;&gt;
            You are in: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">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;">breadcrumbs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLinkLast</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMinDepth</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</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: #000000; font-weight: bold;">?&gt;</span>
        &lt;/div&gt;
        &lt;div id=&quot;content&quot;&gt;
            Content of your page here.
        &lt;/div&gt;
    &lt;/body&gt;
&lt;html&gt;</pre></div></div>

<p><strong>More reading:</strong><br />
If you have time, check out <a href="http://www.zendcasts.com/zend_navigation-dynamically-creating-a-menu-a-sitemap-and-breadcrumbs/2009/06/">Jonathan Lebensold&#8217;s screencast</a> found in ZendCasts. It is an excellent tutorial and it goes all the way to beautifying your navigation using tabs and your breadcrumbs.</p>
<p>And lastly, the Zend_Navigation documentation can be found <a href="http://framework.zend.com/manual/en/zend.navigation.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2009/06/10/zend-framework-navigation-and-breadcrumbs-with-an-xml-file-in-zf-18/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.572 seconds -->
<!-- Cached page served by WP-Cache -->
