<?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/"
	>

<channel>
	<title>echolibre blog &#187; Zend Framework</title>
	<atom:link href="http://blog.echolibre.com/category/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.echolibre.com</link>
	<description></description>
	<pubDate>Mon, 25 Apr 2011 20:44:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>LIKE conditions with Zend_Db_Select</title>
		<link>http://blog.echolibre.com/2010/08/sql-where-like-with-zend_db_select/</link>
		<comments>http://blog.echolibre.com/2010/08/sql-where-like-with-zend_db_select/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 09:38:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://blog.echolibre.com/?p=993</guid>
		<description><![CDATA[Despite all the implications of using LIKE in MySQL, sometimes it&#8217;s quite useful for a proof-of-concept to be able to use it.
Even though this is a rather trivial example, I hope it will be of help to whoever is wondering how to use a LIKE in a where using a Zend_Db_Select::where() or Zend_Db_Select::orWhere() and did [...]]]></description>
			<content:encoded><![CDATA[<p>Despite all the implications of using LIKE in MySQL, sometimes it&#8217;s quite useful for a <em>proof-of-concept</em> to be able to use it.</p>
<p>Even though this is a rather trivial example, I hope it will be of help to whoever is wondering how to use a LIKE in a where using a <a title="Zend Framework Database DB Select Where" href="http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.where">Zend_Db_Select::where()</a> or Zend_Db_Select::orWhere() and did not manage to find decent documentation about it.</p>
<p><span id="more-993"></span></p>
<script src="http://gist.github.com/534198.js"></script>
<p>As you can see, we bind a parameter to the <em>where()</em> method using the <strong>?</strong> symbol, then when assigning the value of this parameter — second parameter — we append the wildcard character <strong>%</strong>. The new binded parameter value is then <em>string%</em> and which gets quoted and executed giving you the expected output.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2010/08/sql-where-like-with-zend_db_select/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Guest Post: Ben Chapman&#8217;s week of code</title>
		<link>http://blog.echolibre.com/2010/02/guest-post-ben-chapmans-week-of-code/</link>
		<comments>http://blog.echolibre.com/2010/02/guest-post-ben-chapmans-week-of-code/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:42:13 +0000</pubDate>
		<dc:creator>Eamon</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://blog.echolibre.com/?p=841</guid>
		<description><![CDATA[This post is by Ben Chapman, a 5th year student in Scoil Mhuire Clane, who is with us for a week on work experience.
Hello! The guys here at echolibre thought that making a web app would be the best way for me to experience working in this industry, so I am. The idea that I&#8217;ve come [...]]]></description>
			<content:encoded><![CDATA[<h2>This post is by <a title="Ben Chapman on Twitter" href="http://twitter.com/thejetset" target="_self">Ben Chapman</a>, a 5th year student in <em>Scoil Mhuire Clane</em>, who is with us for a week on work experience.</h2>
<p>Hello! The guys here at echolibre thought that making a web app would be the best way for me to experience working in this industry, so I am. The idea that I&#8217;ve come up with and started this week is, as Eamon put it, <strong>a document management system for schools, teachers &amp; students</strong>.  Here&#8217;s just a quick overview of what I want to do with the project and I&#8217;d love to hear what you think about it or any ideas you have &#8212; so if you want to, just throw me a comment below!<span id="more-841"></span></p>
<p>Basically, the idea is to have a platform that enables those who participate in a school environment to share resources much more easily and to make it easier to find the relevant resources faster. Included in this would be a &#8220;homework journal&#8221; style system to allow the student to see exactly what they have to do and allow them to organise it more efficiently and with almost one-click access to very relevant resources chosen by the teacher to go along with that work.</p>
<p>This is a largish project and I don&#8217;t expect to get everything done in the week, however, my aims for the end of the week are:</p>
<p>The core of the application, which consists of:</p>
<ul>
<li>Login for school administrators, teachers and a single class based login.</li>
<li>Linking and creation (uploading images, documents, PDFs etc..) of resources for teachers.</li>
<li>The ability to see class assignments for students using the single class based login.</li>
</ul>
<p>What I hope to do with the app in near future:</p>
<ul>
<li>Student logins so that students are presented with a fully customised dashboard that allows them to display everything that they have to do in their &#8220;homework journal&#8221;.</li>
<li>Parent logins so that parents can review the student&#8217;s progress easily.</li>
<li>(a slightly more distant near future I would love to see) a &#8220;marketplace&#8221; where teachers could swap resources they have created for free or for a fee.</li>
</ul>
<p>I have yet to think of a name for this product, so I&#8217;d really love to hear any ideas people would have on that.</p>
<p>David and Eamon have given me advice from a technical and project / commercial perspective.</p>
<p>I&#8217;m using Zend Framework in the LAMP stack. I&#8217;ll update later in the week with progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2010/02/guest-post-ben-chapmans-week-of-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to build an API in 5 minutes</title>
		<link>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/</link>
		<comments>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 15:44:17 +0000</pubDate>
		<dc:creator>Eamon</dc:creator>
		
		<category><![CDATA[API]]></category>

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

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

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

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

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

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

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

		<category><![CDATA[web3.0]]></category>

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

		<guid isPermaLink="false">http://blog.echolibre.com/?p=622</guid>
		<description><![CDATA[On Friday evening we quietly announced on twitter a product that we&#8217;ve been working on for the last 10 months. FRAPI is an Open Source API framework that allows you to open up your existing web based application or legacy system to your own or third party developers.
FRAPI handles standard API things like authentication and [...]]]></description>
			<content:encoded><![CDATA[<p>On Friday evening we quietly announced on twitter a product that we&#8217;ve been working on for the last 10 months. <a href="http://www.getfrapi.com">FRAPI is an Open Source API framework</a> that allows you to open up your existing web based application or legacy system to your own or third party developers.</p>
<p>FRAPI handles standard API things like authentication and data formatting, and speeds up the API development process &#8212; like the way ZF or Symfony for PHP, Django for Python, JQuery for JavaScript (or, I suppose even Ruby on Rails ;-p ), does for other technologies.</p>
<p><a title="David Coallier, CTO, echolibre" href="http://www.twitter.com/DavidCoallier">David Coallier</a> put together a quick 5 minute screencast to show you how you can use FRAPI to start building your API.<span id="more-622"></span></p>
<p><object width="480" height="326" data="http://blip.tv/play/AYGk_BoC" type="application/x-shockwave-flash"><param name="src" value="http://blip.tv/play/AYGk_BoC" /><param name="allowfullscreen" value="true" /></object></p>
<p>FRAPI is about to go into closed beta and we already have a nice list of developers building up. If you&#8217;d like to be part of our closed beta release, you can sign up on <a title="FRAPI - An Open Source API Framework" href="http://www.getfrapi.com">getfrapi.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Customising Zend Framework Routing</title>
		<link>http://blog.echolibre.com/2009/03/customising-zend-framework-routing/</link>
		<comments>http://blog.echolibre.com/2009/03/customising-zend-framework-routing/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 14:08:25 +0000</pubDate>
		<dc:creator>J.D.</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://blog.echolibre.com/?p=214</guid>
		<description><![CDATA[I wanted to write a post that shows a few different ways to customise Zend Frameworks routing when you&#8217;re using their MVC implementation. Most of this is covered in the documentation, but it can be a little difficult to dig out.
The standard routing setup of Zend matches URLs like these:

1
2
www.example.com/module/controller/action/var1/value1/var2/value2
www.example.com/controller/action/var1/value1/var2/value2

You set your controller directories in [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to write a post that shows a few different ways to customise Zend Frameworks routing when you&#8217;re using their MVC implementation. Most of this is covered in the <a href="http://framework.zend.com/manual/en/zend.controller.router.html">documentation</a>, but it can be a little difficult to dig out.</p>
<p>The standard routing setup of Zend matches URLs like these:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">www<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>module<span style="color: #339933;">/</span>controller<span style="color: #339933;">/</span>action<span style="color: #339933;">/</span>var1<span style="color: #339933;">/</span>value1<span style="color: #339933;">/</span>var2<span style="color: #339933;">/</span>value2
www<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>controller<span style="color: #339933;">/</span>action<span style="color: #339933;">/</span>var1<span style="color: #339933;">/</span>value1<span style="color: #339933;">/</span>var2<span style="color: #339933;">/</span>value2</pre></td></tr></table></div>

<p>You set your controller directories in your bootstrap with something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setControllerDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'../controllers'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bar'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'../modules/bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foo'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'../modules/foo'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>For the first component of the path Zend will first look for a matching module, if none is found it will look for a matching controller. The module name &#8216;default&#8217; is important here; it represents (surprisingly) the default controllers. So these are the ones when there&#8217;s no matching module in the URL.<br />
<span id="more-214"></span></p>
<h2>Now on to the magic&#8230;</h2>
<p>The original reason I started delving into all this was because I wanted to have a url without specifying an action, yet still have variables. I also wanted this broken into modules like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">www<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>foo<span style="color: #339933;">/</span>eek<span style="color: #339933;">/</span>var1<span style="color: #339933;">/</span>value1<span style="color: #339933;">/</span>var2<span style="color: #339933;">/</span>value2</pre></td></tr></table></div>

<p>&#8230; to resolve to the module &#8216;foo&#8217;, the controller &#8216;eek&#8217;, and pass the parameters var1, var2. To do this I set up the following route:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route<span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">':module/:controller/*'</span><span style="color: #339933;">,</span>
<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$router</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The router will try to match a url against the pattern specified as the first argument to the constructor. It uses a simple syntax where any word preceded by a &#8216;:&#8217; is a variable, and a * will match anything that follows. The variables <em>module</em>, <em>controller</em> and <em>action</em> are special names. They refer to where the query should be routed to. Hence the pattern above will match /foo/bar/a/b to module = foo, controller = bar, and the parameter a = b. The action of <em>index</em> is specified in the second parameter. This array can be used to give defaults to any parameters you expect, or module/controller/action.</p>
<p>When adding a route the first parameter is just a label, it doesn&#8217;t have any influence. If you specify the same label twice the second will overwrite the first. So if you want to overwrite the default route then use the label &#8216;default&#8217;. As you add more routes they&#8217;re matched in the reverse order to which they&#8217;re added.</p>
<p>Finally I wanted to override the default way parameters are passed. Given the URL:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">www<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>foo<span style="color: #339933;">/</span>eek<span style="color: #339933;">/</span>a<span style="color: #339933;">/</span>b<span style="color: #339933;">/</span>c<span style="color: #339933;">/</span>d</pre></td></tr></table></div>

<p>&#8230; the parameters passed to the controller are (&#8217;a'=&gt;&#8217;b',&#8217;c'=&gt;&#8217;d'). I wanted a variable number of parameters to be passed in, but for none of them to be named. It should result in a parameter array of (1=&gt;&#8217;a',2=&gt;&#8217;b',3=&gt;&#8217;c',4=&gt;&#8217;d'). To do this you can extend the Zend_Controller_Router_Route class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyRoute <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Router_Route
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> match<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #339933;">===</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_wildcardData <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$results</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$vars</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This solution is a bit of a hack*, but it works <img src='http://blog.echolibre.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Each subclass of Zend_Controller_Router_Abstract has a method called <em>match</em>. This method is passed the path, and returns either false if the route doesn&#8217;t match the path or an array of results if it does. The array will contain the module, controller and action; as well as the parameters to be passed to the action.</p>
<p>The above code uses the standard routers match function, then doctors the resultant array so that it&#8217;s the way I want it. _wildcardData is an array that&#8217;s built up during the parent&#8217;s match method, containing all the parameters.</p>
<p>To use it, just treat it as you would a normal route:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyRoute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':module/:controller/*'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #339933;">,</span><span style="color: #000088;">$route</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Interesting stuff can also be done with <a href="http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.regex">Zend_Controller_Router_Route_Regex</a>, but I don&#8217;t think you can make it have a variable number of parameters.</p>
<p>*Please God no one bring up the <a href="http://en.wikipedia.org/wiki/Call_super">call super</a> antipattern&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2009/03/customising-zend-framework-routing/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

