<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.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>www.DOHDOH.net</title>
	<link>http://www.dohdoh.net</link>
	<description></description>
	<pubDate>Tue, 08 Apr 2008 03:27:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Zend Framework Tutorial Part 2 ( UI Components with Site Layout, Site Navigations and Forms )</title>
		<link>http://www.dohdoh.net/2008/04/08/zend-framework-tutorial-part-2-ui-components-with-site-layout-site-navigations-and-forms/</link>
		<comments>http://www.dohdoh.net/2008/04/08/zend-framework-tutorial-part-2-ui-components-with-site-layout-site-navigations-and-forms/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 02:54:01 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[Zend Framework]]></category>

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

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

		<category><![CDATA[Website Design and Application]]></category>

		<guid isPermaLink="false">http://www.dohdoh.net/2008/04/08/zend-framework-tutorial-part-2-ui-components-with-site-layout-site-navigations-and-forms/</guid>
		<description><![CDATA[In this part of our tutorial we will be building our application's front end ( default module ), constructing the links, creating and validating a form and using FlashMessenger to form errors.
Let's take a look at some of the pages in our application.


“Home” and “About Site” just displays a static page and thus we haven't [...]]]></description>
			<content:encoded><![CDATA[<p>In this part of our tutorial we will be building our application's front end ( default module ), constructing the links, creating and validating a form and using FlashMessenger to form errors.</p>
<p>Let's take a look at some of the pages in our application.</p>
<p><a href="http://www.dohdoh.net/wp-content/uploads/2008/04/home.png" title="ZF Tutorial Part2 - Home"><img src="http://www.dohdoh.net/wp-content/uploads/2008/04/home.png" alt="ZF Tutorial Part2 - Home" /></a></p>
<p><a href="http://www.dohdoh.net/wp-content/uploads/2008/04/login.png" title="ZF Tutorial Part2 - Login"><img src="http://www.dohdoh.net/wp-content/uploads/2008/04/login.png" alt="ZF Tutorial Part2 - Login" /></a></p>
<p>“Home” and “About Site” just displays a static page and thus we haven't included “About Site” page in our screenshots. The other two, “Register” and “Login”, includes a form for the user to fill-up and for us to validate.</p>
<p>Our directory structure for our default module will be like the screenshot below.</p>
<p><a href="http://www.dohdoh.net/wp-content/uploads/2008/04/default-module-directory-structure.png" title="ZF Tutorial Part2 - Directory Structure"><img src="http://www.dohdoh.net/wp-content/uploads/2008/04/default-module-directory-structure.png" alt="ZF Tutorial Part2 - Directory Structure" /></a></p>
<p>The uniformity of our pages look was done through our use of Zend_Layout, one of the most useful feature, in building a web application.</p>
<p>In our previous post, we declared in pur bootstrap file that we will be using MVC for our aplication and defined the directory our template files. So, Let's take a look at the important part our template file ( templates/front.phtml ), the full source code of our working applicatio can be downloaded at the end of our tutorial.</p>
<p>1.) The code below creates the title tag in our html part ( including the title tag itself ). The prepend method tells that we will insert the string “ZF Connections” in or every page and adds a separator of “::”. We could see the effect of this on the screenshots displayed above.</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headTitle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">prepend</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ZF Connections'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headTitle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">setSeparator</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">' :: '</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headTitle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>2.) The next code below includes the css files in our application. It will insert all of the necessary attributes for a valid inclusion of css file.</p>
<pre class="php">&nbsp;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headLink</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">appendStylesheet</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">baseUrl</span> . <span style="color: #ff0000;">'/styles/blueprint/screen.css'</span>, <span style="color: #ff0000;">'screen'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">appendStylesheet</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">baseUrl</span> . <span style="color: #ff0000;">'/styles/blueprint/print.css'</span>, <span style="color: #ff0000;">'print'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">appendStylesheet</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">baseUrl</span> . <span style="color: #ff0000;">'/styles/zf.css'</span>, <span style="color: #ff0000;">'screen'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>3.) The folowing just includes the necessary files located at the same directory as our template file.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'front-top-lang.phtml'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'front-header.phtml'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'front-footer.phtml'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>4.) The following is a little bit different than the previous one, for it wil loop the content of the parameter passed.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partialLoop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'front-navigation.phtml'</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">urls</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// font-navigation.phtml contains the following</span>
&lt;a href=<span style="color: #ff0000;">&quot;&lt;?php echo $this-&gt;url ?&gt;&quot;</span>&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">name</span> ?&gt;&lt;/a&gt; |
&nbsp;
<span style="color: #808080; font-style: italic;">// and urls is declared in the basecontroller as</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getLinks<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0000ff;">$url</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Url'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span> =&gt; <span style="color: #ff0000;">'Home'</span>,
<span style="color: #ff0000;">'url'</span> =&gt; <span style="color: #0000ff;">$url</span>-&gt;<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,
<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span> =&gt; <span style="color: #ff0000;">'About Site'</span>,
<span style="color: #ff0000;">'url'</span> =&gt; <span style="color: #0000ff;">$url</span>-&gt;<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'about-site'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,
<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span> =&gt; <span style="color: #ff0000;">'Register'</span>,
<span style="color: #ff0000;">'url'</span> =&gt; <span style="color: #0000ff;">$url</span>-&gt;<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'register'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,
<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span> =&gt; <span style="color: #ff0000;">'Login'</span>,
<span style="color: #ff0000;">'url'</span> =&gt; <span style="color: #0000ff;">$url</span>-&gt;<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'login'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//and set on the init method</span>
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">urls</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getLinks</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>5.) The most important and the simplest part of our layout will be displaying the actual content of the controller called.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">layout</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">content</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>We have seen the layout.phtml and now its time to delve into our controlelr classes.</p>
<p>We will discuss the abstract BaseController class upon which all of our controllers on our default module extends upon. BaseController does the work of initializing our FlashMessenger, setting the baseUrl on the view, setting the the layout and links, and other methods.</p>
<p>We have three protected methods on our BaseController class, 1.) validateForm which accepts a Zend_Form instance as its first parameter and the array of data to validate upon,  2.) redirectToController which accepts a controller name and an optional action name as its second parameter, and 3.) addSucessMessage which takes a stirng parameter as message and store it in our flashMessenger.</p>
<p>We have also another helper controller namely the FlashMessagesController. It's only job is to fetch all the messages stored on our FlashMessenger and display it as well as parse upon which kind of message is stored ( success, notice, or error ). We will be including this action through one of view's helper, namely action helper ( nice name ).</p>
<p>Its only method, indexAction, contains the following code:</p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">hasMessages</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0000ff;">$display_messages</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$messages</span> = <span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">getMessages</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$messages</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$message</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$message</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'type'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0000ff;">$type</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'='</span>, <span style="color: #0000ff;">$message</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">messages_type</span> = <span style="color: #0000ff;">$type</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0000ff;">$display_messages</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$message</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">messages</span>      = <span style="color: #0000ff;">$display_messages</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// and this will be the phtml file for displaying our message</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">messages</span> &amp;&amp; <a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">messages</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $this-&gt;messages_type ?&gt;&quot;</span> style=<span style="color: #ff0000;">&quot;width:350px&quot;</span> align=<span style="color: #ff0000;">&quot;left&quot;</span>&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">messages</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">formErrors</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">messages</span><span style="color: #66cc66;">&#41;</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: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">messages</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<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;
&nbsp;
<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;</pre>
<p>Our IndexController and AboutSiteController are pretty straightforward and just displays their properly configured view file. We have configured these controller files to load the view file in a separate directory, instead of their default ones. The code looks like the following:</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// IndexController ( indexAction )</span>
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'home'</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// AboutSiteController ( indexAction )</span>
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'about-site'</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>This line of code tells us that we will load the about-site.phtml in top directory of views folder, meaning not under any controller specific subdirectory ( the true argument on render particulary says that the view does not have a controller ). The second argument (null ),  simply tells that we will be including all the segment of the response object.</p>
<p>Now we'll have to take a look at our RegisterController. RegisterController does some other things beside displaying the register page. In this controller, we will creae a Zend_Form to be included in the view area, validates our form after submission and displays messages based on the result of validation ( success or error ).</p>
<p>We first take a look at the creation of form defined on the getForm() method on our RegisterController.</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$form</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">setAction</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;_request-&gt;<span style="color: #006600;">getBaseUrl</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">'/'</span>
. <span style="color: #0000ff;">$this</span>-&gt;_request-&gt;<span style="color: #006600;">getControllerName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">'/signup'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">setMethod</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'post'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$email</span> = <span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'text'</span>, <span style="color: #ff0000;">'email'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'class'</span> =&gt; <span style="color: #ff0000;">'text'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$email</span>-&gt;<span style="color: #006600;">addValidator</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'EmailAddress'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">setRequired</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">addFilter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'StringToLower'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">addFilter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'StringTrim'</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">setLabel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Email Address'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$submit</span> = <span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'button'</span>, <span style="color: #ff0000;">' Submit '</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type'</span> =&gt; <span style="color: #ff0000;">'submit'</span>, <span style="color: #ff0000;">'class'</span> =&gt; <span style="color: #ff0000;">'button'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">addElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$email</span><span style="color: #66cc66;">&#41;</span>
-&gt;<span style="color: #006600;">addElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$submit</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$form</span>;
&nbsp;</pre>
<p>Creating of Zend_Form is pretty straightforwad, the trivial part is the creation of its action. We didn't hard-code the action of our form so that our form will be more flexible and we won't be changing any the form's properties.</p>
<p>Our email element was created through the form's createElement method. We have created a input element with type of text, with name of email and a class of text.<br />
We have added a validator for the element, EmailAddress, or we could have written the validation just like the following instead:<br />
$email->addValidator(new Zend_Validate_EmailAddress());</p>
<p>And we have added some filters, StringToLower and StringTrim, which are quite straightforward. And lastly we have added a label to the element.</p>
<p>The next element on our form is the submit button. we have used button element with type of submit.</p>
<p>After the two elements were created, we have added the two elements back on the form for display.</p>
<p>Our signupAction which do the validation of our form is as simple as the following code:</p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;_request-&gt;<span style="color: #006600;">isPost</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">redirectToController</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">validateForm</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getForm</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">redirectToController</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$message</span>  = <span style="color: #ff0000;">'
&nbsp;
Thank you for joining ZF Connections
&nbsp;
'</span>;
<span style="color: #0000ff;">$message</span> .= <span style="color: #ff0000;">'
&nbsp;
Your login credentials will be submitted in the email that you have provided.
&nbsp;
'</span>;
<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">addSuccessMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$message</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">redirectToController</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>First we, checked is submitted via post method. The next checking is actually checking of forms for theie errors. If the form does not have any errors we just display a message ( for now ). All of the following cases will end up redirecting to the “register” controller.</p>
<p>The validateForm method on our BaseController is defined as follows:</p>
<pre class="php">&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> validateForm<span style="color: #66cc66;">&#40;</span>Zend_Form <span style="color: #0000ff;">$form</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">isValid</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">getMessages</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$field</span> =&gt; <span style="color: #0000ff;">$message</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$message</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">addMessage</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strtoupper"><span style="color: #000066;">strtoupper</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$field</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">' '</span> . <span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">addMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type=error'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>The method checks the form and add any errors generated and add it to our flashMessenger.</p>
<p>LoginController is almost the same as RegisterController, the only difference is that LoginController has an additional element on its form which is the password element. You can download our working application below and take a look on how we have glued together our application.</p>
<p>Our next topic will be creating a Model for database interaction and finishing up our registration and login. We will be using more ZF classese like Zend_Auth, Zend_Acl, Zend_Log and other classes we may need as we code.</p>
<p>See you next time and happy coding! =)<br />
Download Files Here ( Zend Framework is not included in the zip file dure to file limitation ):<br />
<a href="http://www.dohdoh.net/wp-content/uploads/2008/04/zf-part2.zip" title="ZF Tutorial Part2 - Files">ZF Tutorial Part2 - Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2008/04/08/zend-framework-tutorial-part-2-ui-components-with-site-layout-site-navigations-and-forms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zend Framework Tutorial Part 1 (Directory Structure and Bootstrap File)</title>
		<link>http://www.dohdoh.net/2008/04/04/zend-framework-tutorial-part-1-directory-structure-and-bootstrap-file/</link>
		<comments>http://www.dohdoh.net/2008/04/04/zend-framework-tutorial-part-1-directory-structure-and-bootstrap-file/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 03:03:51 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[Zend Framework]]></category>

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

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

		<category><![CDATA[Website Design and Application]]></category>

		<guid isPermaLink="false">http://www.dohdoh.net/2008/04/04/zend-framework-tutorial-part-1-directory-structure-and-bootstrap-file/</guid>
		<description><![CDATA[Note: This tutorial is intended for intermediate PHP users.
Our project for this tutorial, ZF Connections (a social networking site), will be designed in such a way that adding a functionality will be as easy as possible by extending it using a module. This tutorial assumes the reader of familiarity of PHP5 and OOP terminologies.
Our application [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Note: This tutorial is intended for intermediate PHP users.</strong></em></p>
<p>Our project for this tutorial, ZF Connections (a social networking site), will be designed in such a way that adding a functionality will be as easy as possible by extending it using a module. This tutorial assumes the reader of familiarity of PHP5 and OOP terminologies.</p>
<p>Our application will be divided into three main modules, admin module, members module, and the default/application module. The first module (admin module) will be used for administrative tasks on our application,  the members module will focus more on the members/users of the application and the third one, default/application module, will be focusing on the overall or general part of our application.</p>
<p>Now that we have the basic requirement for our application, let's begin to dig a little deeper. For our admin module, all modules installed must be accessible only through the following url: http://localhost/admin/<module-name>/, as well as the members module must only be accessible in http://localhost/members/<module-name>/. The default/application modules must be accessed regularly as http://localhost/<module-name>/. The problem here is that we must have a directory structure upon which adding a directory under some “modules” directory will automatically create the route/url for us and its controllers and models will be properly included and initialized.</module-name></module-name></module-name></p>
<p>The directory structure I have come up with was like this:</p>
<p>-- [root]<br />
---- _tests<br />
---- application<br />
------ admin<br />
------ default<br />
------ members<br />
------ modules<br />
-------- default<br />
-------- members<br />
-------- admin<br />
------ templates<br />
---- html<br />
---- library<br />
---- resources</p>
<p>Our directory structure has five top-level directories, but only four will be deployed ( _tests, application, html, library, resources ).</p>
<p>_tests directory will contain all of our test cases</p>
<p>application directory will contain our modules (default modules and sub-modules)</p>
<p>html directory will contain all files visible to the public ( images, js, css, view files )</p>
<p>library directory will contain all of the classes that we will be using including the Zend Framework, and other classes as we go along into our tutorial.</p>
<p>resources directory will contain all of our configuration files.</p>
<p>Let's take another look at our application directory.<br />
-- application<br />
---- admin<br />
---- default<br />
---- members<br />
---- modules<br />
------ admin<br />
------ default<br />
------ members<br />
---- templates</p>
<p>The three subdirectories ( admin, defualt, members ) will be our default or predefined modules in our application, “default” is a predefined module in Zend Framework.<br />
The other directory, modules, on which there are three subdirectories on which the three predefined modules are named alike plays a significant role in our application design. Every modules defined on one of the subfolders will be automatically included as a submodule of our predefined module. Consider the follwing module example module placed under modules/members</p>
<p>---- modules<br />
------ members<br />
-------- message<br />
---------- controllers<br />
---------- models<br />
---------- views</p>
<p>The message module upon placing it under the members module will automatically qualify it as a submodule of members module. Whew! The message module can now be accessed through the following url: http://localhost/members/message/  .<br />
Every modules placed under the subdirectories of our predefined module names ( as well as other module names ) under modules directory will also be rerouted correctly.</p>
<p>Placing other inside other module name directory beside our predefined subdirectory is also possible. Consider the following example.</p>
<p>---- modules<br />
------ others<br />
-------- other<br />
---------- controllers<br />
---------- models<br />
---------- views</p>
<p>The follwing module can be accessed through the url:<br />
http://localhost/others/other</p>
<p>The magic(logic) behind accessing and plugging module is in our bootstrap file.<br />
It's time we take a look at our bootstrap file and dissect it part by part later. We will not be talking the classes involved in detail, we will only discuss it in depth as soon as we will be using it extensively or in a major part of the application.</p>
<p>This is our index.php file.</p>
<style>pre {font-size:1.0em;}</style>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">/**
 * Zend Framework Tutorial
 *
 * @author Ronald de Leon
 * @version 1.0
 */</span>
&nbsp;
<a href="http://www.php.net/error_reporting"><span style="color: #000066;">error_reporting</span></a><span style="color: #66cc66;">&#40;</span>E_ALL|E_STRICT<span style="color: #66cc66;">&#41;</span>;
date_default_timezone_set<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Asia/Manila'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SYSTEM_PATH'</span>, <a href="http://www.php.net/dirname"><span style="color: #000066;">dirname</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">__FILE__</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'APPLICATION_PATH'</span>, <a href="http://www.php.net/dirname"><span style="color: #000066;">dirname</span></a><span style="color: #66cc66;">&#40;</span>SYSTEM_PATH<span style="color: #66cc66;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'application'</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'RESOURCE_PATH'</span>, <a href="http://www.php.net/dirname"><span style="color: #000066;">dirname</span></a><span style="color: #66cc66;">&#40;</span>SYSTEM_PATH<span style="color: #66cc66;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'resources'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// set include path to include files in our library directory on which the</span>
<span style="color: #808080; font-style: italic;">// zend framework is located</span>
<a href="http://www.php.net/set_include_path"><span style="color: #000066;">set_include_path</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/get_include_path"><span style="color: #000066;">get_include_path</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> . PATH_SEPARATOR
				  . <a href="http://www.php.net/dirname"><span style="color: #000066;">dirname</span></a><span style="color: #66cc66;">&#40;</span>SYSTEM_PATH<span style="color: #66cc66;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'library'</span>
				<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// load Zend_Loader class and make it automatically auto load all of our classes,</span>
<span style="color: #808080; font-style: italic;">// no more long includes/requires and Zend_Loader::loadClass</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Loader.php'</span>;
Zend_Loader::<span style="color: #006600;">registerAutoload</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// // setup database config file by loading configuration through our ini file located at resource directory</span>
<span style="color: #0000ff;">$dbConfig</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #66cc66;">&#40;</span>RESOURCE_PATH . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'database-config.ini'</span>, <span style="color: #ff0000;">'staging'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// setup database resource through our config file</span>
<span style="color: #0000ff;">$db</span> = Zend_Db::<span style="color: #006600;">factory</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dbConfig</span>-&gt;<span style="color: #006600;">database</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// set db to be used as default default adapter in all of our application models</span>
Zend_Db_Table_Abstract::<span style="color: #006600;">setDefaultAdapter</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$db</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// set-up layout options to be used for our project</span>
<span style="color: #0000ff;">$layoutOptions</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">'layoutPath'</span> =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'templates'</span>, <span style="color: #808080; font-style: italic;">// our template directory</span>
	<span style="color: #ff0000;">'layout'</span>	 =&gt; <span style="color: #ff0000;">'front'</span> <span style="color: #808080; font-style: italic;">// our default layout</span>
<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// set layout configuration to Zend_Layout class</span>
Zend_Layout::<span style="color: #006600;">startMvc</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$layoutOptions</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// define default modules directory</span>
<span style="color: #0000ff;">$defaultModules</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">'default'</span> =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'default'</span>,
	<span style="color: #ff0000;">'members'</span> =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'members'</span>,
	<span style="color: #ff0000;">'admin'</span>   =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'admin'</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// get front controller instance</span>
<span style="color: #0000ff;">$controller</span> = Zend_Controller_Front::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// get router from front controller</span>
<span style="color: #0000ff;">$router</span> = <span style="color: #0000ff;">$controller</span>-&gt;<span style="color: #006600;">getRouter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// iterate default modules</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$defaultModules</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$module</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// add default controller directories</span>
		<span style="color: #0000ff;">$controller</span>-&gt;<span style="color: #006600;">addControllerDirectory</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$module</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'controllers'</span>, <span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// add models directory to include path</span>
		<a href="http://www.php.net/set_include_path"><span style="color: #000066;">set_include_path</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/get_include_path"><span style="color: #000066;">get_include_path</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> . PATH_SEPARATOR . <span style="color: #0000ff;">$module</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'models'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$controller</span>-&gt;<span style="color: #006600;">throwExceptions</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// should be turned on in development time</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// define modules directory</span>
<span style="color: #0000ff;">$moduleFolder</span> = APPLICATION_PATH  . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'modules'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// this is where the code that makes our application extendable through modules</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$modules</span> = scandir<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$moduleFolder</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//scan module folder for saved modules (top level modules will be scanned {application, members})</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$modules</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$module</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$module</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">continue</span>; <span style="color: #808080; font-style: italic;">// if search directory starts with a dot, skip directory</span>
&nbsp;
		<span style="color: #0000ff;">$subModulePath</span> = <span style="color: #0000ff;">$moduleFolder</span> . DIRECTORY_SEPARATOR . <span style="color: #0000ff;">$module</span>; <span style="color: #808080; font-style: italic;">// this will be the submodules directory directly under parent module. e.g. application</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #000066;">is_dir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$subModulePath</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #0000ff;">$subModules</span> = scandir<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$subModulePath</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// scan the submodules directory for specific modules defined</span>
&nbsp;
			<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$subModules</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$singleModule</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$singleModule</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">continue</span>; <span style="color: #808080; font-style: italic;">// if search directory starts with a dot, skip directory</span>
&nbsp;
				<span style="color: #0000ff;">$modulePath</span> = <span style="color: #0000ff;">$subModulePath</span> . DIRECTORY_SEPARATOR . <span style="color: #0000ff;">$singleModule</span>; <span style="color: #808080; font-style: italic;">// this will be the actual module or specific module found</span>
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #000066;">is_dir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$modulePath</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
					<span style="color: #808080; font-style: italic;">// add to include path, models directory</span>
					<a href="http://www.php.net/set_include_path"><span style="color: #000066;">set_include_path</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/get_include_path"><span style="color: #000066;">get_include_path</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> . PATH_SEPARATOR
							. <span style="color: #0000ff;">$modulePath</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'models'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
					<span style="color: #808080; font-style: italic;">// add controllers to controller directory</span>
					<span style="color: #0000ff;">$controller</span>-&gt;<span style="color: #006600;">addControllerDirectory</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$modulePath</span> . DIRECTORY_SEPARATOR . <span style="color: #ff0000;">'controllers'</span>, <span style="color: #0000ff;">$singleModule</span><span style="color: #66cc66;">&#41;</span>;	
&nbsp;
					<span style="color: #808080; font-style: italic;">// add to router</span>
					<span style="color: #808080; font-style: italic;">// if module is under application set router to default directory</span>
					<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$module</span> == <span style="color: #ff0000;">'default'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
						<span style="color: #0000ff;">$router</span>-&gt;<span style="color: #006600;">addRoute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span>, <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$singleModule</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
						<span style="color: #808080; font-style: italic;">// if module is under not a member of default module set router to /${module}/{singleModule}</span>
						<span style="color: #0000ff;">$router</span>-&gt;<span style="color: #006600;">addRoute</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$module</span> . <span style="color: #ff0000;">'/'</span> . <span style="color: #0000ff;">$singleModule</span>, <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$module</span> . <span style="color: #ff0000;">'/'</span> . <span style="color: #0000ff;">$singleModule</span>,
							<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
								<span style="color: #ff0000;">'module'</span>	 =&gt; <span style="color: #0000ff;">$singleModule</span>,
								<span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'index'</span>
							<span style="color: #66cc66;">&#41;</span>
						<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #66cc66;">&#125;</span>
&nbsp;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// end checking {is_dir($modulePath)} </span>
&nbsp;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// end loop of submodules directory</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// end checking {is_dir($subModulePath)}</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// end looping of modules directory</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// end group bracket</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// run application</span>
<span style="color: #0000ff;">$controller</span>-&gt;<span style="color: #006600;">dispatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>The first two lines of code in our framework will be setting some important configuration. Setting error reporting to ALL or STRICT, and setting default timezone to Manila, Philippines.</p>
<p>The next lines defines some paths to be used in accessing certain files in our layout such as the APPLICATION_PATH and RESOURCE_PATH.</p>
<p>The following line loads Zend_Loader and tells the class to automatically load all defined class.</p>
<p>require_once 'Zend/Loader.php';<br />
Zend_Loader::registerAutoload();</p>
<p>The next lines of code setup our database connection by specifying and loading the configuration thru a database-config.ini file located in our top-level resource directory and loaded it through Zend_Config_Ini to be automatically parse our ini file. The 'staging' part is a way to tell Zend_Config_Ini that we will be using the 'staging' part in the config file. We chose to use Zend_Config_Ini instead of Zend_Config_Xml because the codes are easier to read in an ini file than in an xml file.</p>
<p>We get the db adapter or resource from Zend_Db class by passing our config object. The last part tells that we should always or our db adapter defined here will be used if no adapter is specified. Our DB adapter is of type Zend_Db_Adapter_Pdo_Mysql, it automatically detects to load the particular class by parsing our ini file.</p>
<p>// // setup database config file by loading configuration through our ini file located at resource directory<br />
$dbConfig = new Zend_Config_Ini(RESOURCE_PATH . DIRECTORY_SEPARATOR . 'database-config.ini', 'staging');</p>
<p>// setup database resource through our config file<br />
$db = Zend_Db::factory($dbConfig-&gt;database);</p>
<p>// set db to be used as default default adapter in all of our application models<br />
Zend_Db_Table_Abstract::setDefaultAdapter($db);</p>
<p>// filename: database-config.ini<br />
// our database configuration<br />
; Production site configuration data<br />
[production]<br />
database.adapter         = pdo_mysql<br />
database.params.host     = dbhost<br />
database.params.username = dbuser<br />
database.params.password = dbpassword<br />
database.params.dbname   = dbname</p>
<p>; Staging site configuration data inherits from production and<br />
; overrides values as necessary<br />
[staging : production]<br />
database.params.host     = localhost<br />
database.params.username = root<br />
database.params.password =<br />
database.params.dbname   = zfconnections_development<br />
database.params.profiler = true</p>
<p>The following defines our layout options and set the options to our Zend_Layout class. Upon callinf the startMvc method, our application assumes that we will be using layouts for our application on which the layouts wil be located on the paths specified in our 'layoutPath' and our default layout if none specified will be 'front'.</p>
<p>// set-up layout options to be used for our project<br />
$layoutOptions = array(<br />
'layoutPath' =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . 'templates', // our template directory<br />
'layout'	 =&gt; 'front' // our default layout<br />
);<br />
// set layout configuration to Zend_Layout class<br />
Zend_Layout::startMvc($layoutOptions);</p>
<p>In the codes below, we define our default modules in an array so that we could iterate overt it at a later time. Instantiate our fromt controller by calling its static method getInstance(), retrieve the router object from our front controller and iterate our default module directory so that its 'controllers' directory will be added in our front controller's controller directory and our models directory will be added in our include_path.</p>
<p>// define default modules directory<br />
$defaultModules = array(<br />
'default' =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . 'default',<br />
'members' =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . 'members',<br />
'admin'   =&gt; APPLICATION_PATH . DIRECTORY_SEPARATOR . 'admin'<br />
);</p>
<p>// get front controller instance<br />
$controller = Zend_Controller_Front::getInstance();</p>
<p>// get router from front controller<br />
$router = $controller-&gt;getRouter();</p>
<p>// iterate default modules<br />
{<br />
foreach($defaultModules as $key =&gt; $module) {</p>
<p>// add default controller directories<br />
$controller-&gt;addControllerDirectory($module . DIRECTORY_SEPARATOR . 'controllers', $key);</p>
<p>// add models directory to include path<br />
set_include_path(get_include_path() . PATH_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'models');</p>
<p>}<br />
}</p>
<p>The code below tells that we will be throwing some exceptions.<br />
And it SHOULD be turned off on our live site.</p>
<p>$controller-&gt;throwExceptions(true); // should be turned on in development time</p>
<p>The last code is lies the nitty gritty details of our application's secret to its extensible modular design.<br />
The first part tells us where the modules are located.</p>
<p>// define modules directory<br />
$moduleFolder = APPLICATION_PATH  . DIRECTORY_SEPARATOR . 'modules';</p>
<p>this is the part where we scan the modules directory for any directories under it, except if it starts with a dot (.)</p>
<p>The comments on the codes will be enough to tell what the application is doing.</p>
<p>// this is where the code that makes our application extendable through modules<br />
{<br />
$modules = scandir($moduleFolder); //scan module folder for saved modules (top level modules will be scanned {application, members})<br />
foreach ($modules as $module) {</p>
<p>if($module[0] == '.') continue; // if search directory starts with a dot, skip directory</p>
<p>$subModulePath = $moduleFolder . DIRECTORY_SEPARATOR . $module; // this will be the submodules directory directly under parent module. e.g. application<br />
if(is_dir($subModulePath)) {</p>
<p>$subModules = scandir($subModulePath); // scan the submodules directory for specific modules defined</p>
<p>foreach($subModules as $singleModule) {</p>
<p>if($singleModule[0] == '.') continue; // if search directory starts with a dot, skip directory</p>
<p>$modulePath = $subModulePath . DIRECTORY_SEPARATOR . $singleModule; // this will be the actual module or specific module found<br />
if(is_dir($modulePath)) {</p>
<p>// add to include path, models directory<br />
set_include_path(get_include_path() . PATH_SEPARATOR<br />
. $modulePath . DIRECTORY_SEPARATOR . 'models');</p>
<p>// add controllers to controller directory<br />
$controller-&gt;addControllerDirectory($modulePath . DIRECTORY_SEPARATOR . 'controllers', $singleModule);</p>
<p>// add to router<br />
// if module is under application set router to default directory<br />
if($module == 'default') {<br />
$router-&gt;addRoute('', new Zend_Controller_Router_Route($singleModule));<br />
} else {<br />
// if module is under not a member of default module set router to /${module}/{singleModule}<br />
$router-&gt;addRoute($module . '/' . $singleModule, new Zend_Controller_Router_Route($module . '/' . $singleModule,<br />
array(<br />
'module'	 =&gt; $singleModule,<br />
'controller' =&gt; 'index'<br />
)<br />
));<br />
}</p>
<p>} // end checking {is_dir($modulePath)}</p>
<p>} // end loop of submodules directory</p>
<p>} // end checking {is_dir($subModulePath)}</p>
<p>} // end looping of modules directory</p>
<p>} // end group bracket</p>
<p>// run application<br />
$controller-&gt;dispatch();</p>
<p>That's it! Now we have a base design for our application. Next topic we will be discussing on ZF Core components, particularly the MVC components. We will be building the front-end of our application, No database access yet, but we have already defined here our database configuration so theres not much of a problem when we will be using some database access. Our front end development of the application will be focusing on the Zend_Action, Zend_Layout, Zend_View and the our Zend_Form as well on the Request and probably the Response object.</p>
<p>See yah! :-p</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2008/04/04/zend-framework-tutorial-part-1-directory-structure-and-bootstrap-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learning Zend Framework</title>
		<link>http://www.dohdoh.net/2008/04/03/learning-zend-framework/</link>
		<comments>http://www.dohdoh.net/2008/04/03/learning-zend-framework/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 05:28:14 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[Zend Framework]]></category>

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

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

		<category><![CDATA[Website Design and Application]]></category>

		<guid isPermaLink="false">http://www.dohdoh.net/2008/04/03/learning-zend-framework/</guid>
		<description><![CDATA[For the next few days, I would be writing a guide in using the Zend Framework in creating a simple Social Networking Site.
I will be blogging about how to create the site from scratch and help you and myself in learning the Zend Framework and creating a project is the best way to do it. [...]]]></description>
			<content:encoded><![CDATA[<p>For the next few days, I would be writing a guide in using the Zend Framework in creating a simple Social Networking Site.<br />
I will be blogging about how to create the site from scratch and help you and myself in learning the Zend Framework and creating a project is the best way to do it. By the way, we'll be doing the project the agile way! =)</p>
<p>The project will be called ZF Connections, an online community with user profiles, messaging, posting of ads and blogs.</p>
<p>Next post, we will be discussing our directory structure, and how we could separate our modules in their own directories and our bootstrap file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2008/04/03/learning-zend-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pseudo Annotations (@ttribute Oriented Programming) with PHP</title>
		<link>http://www.dohdoh.net/2008/03/14/pseudo-annotations-ttribute-oriented-programming-with-php/</link>
		<comments>http://www.dohdoh.net/2008/03/14/pseudo-annotations-ttribute-oriented-programming-with-php/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 05:49:20 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://www.dohdoh.net/2008/03/14/pseudo-annotations-ttribute-oriented-programming-with-php/</guid>
		<description><![CDATA[ pre {   font-size:1.1em; } 
Attribute-oriented programming (@OP) is a program-level marking technique. Programmers can mark program elements (e.g. classes and methods) to indicate that they maintain application-specific or domain-specific semantics.
With annotations, we could add some "markers" in a class in an unobtrusive way by annotating a property, methods or class inside it's [...]]]></description>
			<content:encoded><![CDATA[<style> pre {   font-size:1.1em; } </style>
<p><a href="http://en.wikipedia.org/wiki/Attribute-Oriented_Programming">Attribute-oriented programming (@OP)</a> is a program-level marking technique. Programmers can mark program elements (e.g. classes and methods) to indicate that they maintain application-specific or domain-specific semantics.</p>
<p>With annotations, we could add some "markers" in a class in an unobtrusive way by annotating a property, methods or class inside it's PHPDoc block. Some of the uses I thought of while doing this article includes.</p>
<p>1. an easy way to inject dependencies (IOC) on methods of a class like an @Inject(<a href="http://code.google.com/p/google-guice/">Google Guice</a>) annotation.</p>
<p>2. a way in marking a class to map with a persistent layer. e.g @table, @column, etc. like in <a href="http://java.sun.com/javaee/overview/faq/persistence.jsp">JPA</a></p>
<p>3. a way in marking a method to log everytime it is called with @log annotation.</p>
<p>The above examples are just 3 of some hundred of uses with annotation based attribute. And the fun part is, the annotations are totally unobtrusive because it is declared inside a PHPDoc block.</p>
<p>An example of an annotated class in PHP is given below:</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
 **  
&nbsp;
 * User entity  
&nbsp;
 *  
&nbsp;
 * @author Ronald A. de Leon  
&nbsp;
 * @table<span style="color: #66cc66;">&#40;</span>name = <span style="color: #ff0000;">'users'</span>, type =<span style="color: #ff0000;">'innodb'</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 */  
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #66cc66;">&#123;</span>  <span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * username of user  
&nbsp;
  *  
&nbsp;
  * @var string  
&nbsp;
  * @id()  
&nbsp;
  * @column(name = 'username', unique = true, updatable = false)  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$username</span>;  
&nbsp;
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * @column(name = 'first_name')  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$firstName</span>;  
&nbsp;
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * @column(updatable = 'true')  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$lastName</span>;  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$notImportant</span>;  
&nbsp;
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * transient property  
&nbsp;
  *  
&nbsp;
  * @var string  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$fullName</span>;  
&nbsp;
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * return username  
&nbsp;
  *  
&nbsp;
  * @return string  
&nbsp;
  * @log(type = 'trace')  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUsername<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">username</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
  * return fullName  
&nbsp;
  *  
&nbsp;
  * @return string  
&nbsp;
  */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFullName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">fullName</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>We have annotated the User class with pseudo annotations like @id, @column, @table. So let's define our goal:<br />
1. We have to properly extract all our custom-based annotations.<br />
2. We have to do something with our extracted data. ( We will discuss this in Part 2 where we will build a simple EntityManager class for our annotated classes )</p>
<p>Our first goal is be able to retrieve all of the values as well as the annotations provided on the class. There are some considerations that we will be dealing. First, we should not parse default annotations provided by PHPDoc ( @var, @param, etc ). Second, a property, method or class can have zero to multiple annotations, and there should be a rule on where an annotation can only be provided in property but not on the class or method level.</p>
<p>So let's start developing our annotation parser and have to address the goals we have defined. The two goals we have given can be combined into one simple goal: "PROVIDE A LOOKUP FOR ALL THE VALID ANNOTATIONS FOR CLASS, METHOD AND PROPERTY."</p>
<p>To address the issue, we will have a static private property on our parser containing our rule. We can store that in an array. Here's the implementations that I came up with:</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #0000ff;">$validAnnotations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 	<span style="color: #ff0000;">'class'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 		<span style="color: #ff0000;">'@table'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span>, <span style="color: #ff0000;">'type'</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 	<span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #ff0000;">'properties'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 		<span style="color: #ff0000;">'@column'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span>, <span style="color: #ff0000;">'insertable'</span>, <span style="color: #ff0000;">'updatable'</span>, <span style="color: #ff0000;">'unique'</span><span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 		<span style="color: #ff0000;">'@id'</span> 	  =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'generator'</span><span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #ff0000;">'methods'</span>	=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 <span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>The key for the implementation of our parser relies on one of the coolest class in PHP, the ReflectionClass. With the ReflectionClass, we could extract all of the metadata for the passed object including the documentation block for the class, methods and properties.</p>
<p>An example of an implementation of the ReflectionClass is as follows:<br />
$reflect = new ReflectionClass(new User());</p>
<p>After the following line, we could now extract all of our needed data, including getting all of the methods and properties of the User object as well as their PHPDoc if there is one. The key of extracting our annotations lies with the 'getDocComment' method. The 'getDocComment' method returns the PHPDoc block of the given data (Reflection family type e.g. ReflectMethod, etc.)</p>
<p>The next thing will just be some simple string matching (RegEx is your friend here ) on the PHPDoc block with our static private rule property as our validator.</p>
<p>Once we have done this, we could extract our gathered data in some kind of 'AnnotationProxy' object where we could referenced the annotated methods, properties, etc.</p>
<p>The code below shows how I implement this behavior. Downloadable files are attached at the end of this article including the UnitTest for our parser (PHPUnit is needed to run the test).</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">/**  
&nbsp;
 * Parser of the Pseudo annotations  
&nbsp;
 *  
&nbsp;
 * @author Ronald A. de Leon  
&nbsp;
 *  
&nbsp;
 */</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AnnotationParser <span style="color: #66cc66;">&#123;</span>	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #0000ff;">$validAnnotations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 	<span style="color: #ff0000;">'class'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 		<span style="color: #ff0000;">'@table'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span>, <span style="color: #ff0000;">'type'</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 	<span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #ff0000;">'property'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 		<span style="color: #ff0000;">'@column'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span>, <span style="color: #ff0000;">'insertable'</span>, <span style="color: #ff0000;">'updatable'</span>, <span style="color: #ff0000;">'unique'</span><span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 		<span style="color: #ff0000;">'@id'</span> 	  =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'generator'</span><span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #66cc66;">&#41;</span>,  
&nbsp;
 	<span style="color: #ff0000;">'method'</span>	=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>  
&nbsp;
 		<span style="color: #ff0000;">'@log'</span>	=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type'</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 	<span style="color: #66cc66;">&#41;</span>  
&nbsp;
 <span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #808080; font-style: italic;">/** uninstantiable, static methods only */</span>  
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> createAnnotatedProxy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$object</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #0000ff;">$r</span> = <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$object</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #0000ff;">$classAnnotations</span> = self::<span style="color: #006600;">setProperties</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'class'</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #0000ff;">$methodAnnotations</span> = self::<span style="color: #006600;">setProperties</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span>-&gt;<span style="color: #006600;">getMethods</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'method'</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #0000ff;">$propertiesAnnotations</span> = self::<span style="color: #006600;">setProperties</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span>-&gt;<span style="color: #006600;">getProperties</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'property'</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> AnnotatedProxy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span>-&gt;<span style="color: #006600;">name</span>, <span style="color: #0000ff;">$classAnnotations</span>, <span style="color: #0000ff;">$methodAnnotations</span>, <span style="color: #0000ff;">$propertiesAnnotations</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> setProperties<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$properties</span>, <span style="color: #0000ff;">$target</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #0000ff;">$arrayToSave</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$properties</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$property</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		self::<span style="color: #006600;">setProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span>, <span style="color: #0000ff;">$target</span>, <span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$arrayToSave</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> setProperty<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span>, <span style="color: #0000ff;">$target</span>, &amp;<span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #0000ff;">$propComment</span> = <span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">getDocComment</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">name</span><span style="color: #66cc66;">&#93;</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span>self::<span style="color: #0000ff;">$validAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$target</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$annotation</span> =&gt; <span style="color: #0000ff;">$validParameters</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #0000ff;">$propAnnotation</span> = self::<span style="color: #006600;">getAnnotationLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$propComment</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$propAnnotation</span> == <span style="color: #000000; font-weight: bold;">null</span> || !<a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$propAnnotation</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// check if string is not empty  </span>
&nbsp;
 			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">name</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 				<a href="http://www.php.net/unset"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">name</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 			<span style="color: #66cc66;">&#125;</span>  
&nbsp;
 			<span style="color: #b1b100;">continue</span>;  
&nbsp;
 		<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">name</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #0000ff;">$lineProps</span> = self::<span style="color: #006600;">getAnnotationLineProperties</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$propAnnotation</span>, <span style="color: #0000ff;">$validParameters</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lineProps</span> &amp;&amp; !<a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lineProps</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 			<span style="color: #0000ff;">$arrayToSave</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span>-&gt;<span style="color: #006600;">name</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$lineProps</span>;  
&nbsp;
 		<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$arrayToSave</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> getAnnotationLine<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$searchString</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #0000ff;">$matches</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/{$name}(.*)/&quot;</span>, <span style="color: #0000ff;">$searchString</span>, <span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #b1b100;">return</span> <a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.php.net/static"><span style="color: #000066;">static</span></a> <span style="color: #000000; font-weight: bold;">function</span> getAnnotationLineProperties<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$annotationLine</span>, <span style="color: #0000ff;">$validParameters</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #0000ff;">$params</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/((.*))/&quot;</span>, <span style="color: #0000ff;">$annotationLine</span>, <span style="color: #0000ff;">$params</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #0000ff;">$map</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 	<span style="color: #0000ff;">$properties</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">', '</span>, <span style="color: #0000ff;">$params</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// $params[0] will return the first match string with '()'  </span>
&nbsp;
 	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$properties</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span> || <a href="http://www.php.net/strpos"><span style="color: #000066;">strpos</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$v</span>, <span style="color: #ff0000;">'='</span><span style="color: #66cc66;">&#41;</span> &lt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 			<span style="color: #b1b100;">continue</span>;  
&nbsp;
 		<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #0000ff;">$tmp</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'='</span>, <span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #0000ff;">$key</span> = <a href="http://www.php.net/strtolower"><span style="color: #000066;">strtolower</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/trim"><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$tmp</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #0000ff;">$value</span> = <a href="http://www.php.net/trim"><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span>, <span style="color: #ff0000;">''</span>, <span style="color: #0000ff;">$tmp</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
 		<span style="color: #0000ff;">$value</span> = <a href="http://www.php.net/strtolower"><span style="color: #000066;">strtolower</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/in_array"><span style="color: #000066;">in_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span>, <span style="color: #0000ff;">$validParameters</span><span style="color: #66cc66;">&#41;</span> || <a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$validParameters</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 			<span style="color: #b1b100;">continue</span>;  
&nbsp;
 		<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #0000ff;">$map</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$value</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$map</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AnnotatedProxy <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$classAnnotations</span>;  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$methodAnnotations</span>;  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$propertyAnnotations</span>;  
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$className</span>;  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$className</span>, <span style="color: #0000ff;">$classAnnotations</span>, <span style="color: #0000ff;">$methodAnnotations</span>, <span style="color: #0000ff;">$propertyAnnotations</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">className</span> 		= <span style="color: #0000ff;">$className</span>;  
&nbsp;
 	<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">classAnnotations</span> 	= <span style="color: #0000ff;">$classAnnotations</span>;  
&nbsp;
 	<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span>	= <span style="color: #0000ff;">$methodAnnotations</span>;  
&nbsp;
 	<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span> 	= <span style="color: #0000ff;">$propertyAnnotations</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getClassName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">className</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getClassAnnotations<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">classAnnotations</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMethodAnnotations<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPropertyAnnotations<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPropertyAnnotationValue<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$column</span>, <span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$property</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$column</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$column</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$column</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 				? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$column</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span><span style="color: #66cc66;">&#93;</span>  
&nbsp;
 				: <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">propertyAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$column</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMethodAnnotationValue<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$method</span>, <span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$property</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$method</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$method</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array_key_exists"><span style="color: #000066;">array_key_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$property</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$method</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>  
&nbsp;
 				? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$method</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span><span style="color: #66cc66;">&#93;</span>  
&nbsp;
 				: <span style="color: #000000; font-weight: bold;">null</span>;  
&nbsp;
 	<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$method</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getClassAnnotationValue<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$annotation</span>, <span style="color: #0000ff;">$property</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>  
&nbsp;
 	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">classAnnotations</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">className</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$annotation</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$property</span><span style="color: #66cc66;">&#93;</span>;  
&nbsp;
 <span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #66cc66;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p><a href="http://www.dohdoh.net/wp-content/uploads/2008/03/attribute-oriented-programming.zip" title="Attribute Oriented Programming in PHP">Download Files Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2008/03/14/pseudo-annotations-ttribute-oriented-programming-with-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating a dynamic finder with PHP</title>
		<link>http://www.dohdoh.net/2008/01/08/creating-a-dynamic-finder-with-php/</link>
		<comments>http://www.dohdoh.net/2008/01/08/creating-a-dynamic-finder-with-php/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 06:02:11 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://www.dohdoh.net/2008/01/08/creating-a-dynamic-finder-with-php/</guid>
		<description><![CDATA[Dynamic finder is a feature of most frameworks today and it works like Model.find_all_by_username or Model.find_by_username_and_password where the two methods are not defined in the model.
So, let’s get started.
We need at least two PHP class here, the model and the dynamic finder builder class.
Lets start with the model.
Class Model {
   const TABLE = [...]]]></description>
			<content:encoded><![CDATA[<p>Dynamic finder is a feature of most frameworks today and it works like Model.find_all_by_username or Model.find_by_username_and_password where the two methods are not defined in the model.</p>
<p>So, let’s get started.</p>
<p>We need at least two PHP class here, the model and the dynamic finder builder class.<br />
Lets start with the model.</p>
<blockquote><p><em>Class Model {</em></p>
<p><em>   const TABLE = ‘users’;</em></p>
<p><em>   public function __call($statement, $parameters) {<br />
$sql = QueryBuilder::getQuery(self::TABLE, $statement, $parameters);<br />
}</em></p>
<p><em>}</em></p>
<p><em>?&gt;</em></p></blockquote>
<p>The model is quite straightforward, we have created a constant variable TABLE so that we could passed that variable to our query builder and delegate its magic method __call to our QueryBuilder class.<br />
<strong> Note: </strong>__call method is automatically called every time an unknown method was invoked on the class.</p>
<p>Let’s take at a look at the QueryBuilder class.<br />
The code is properly documented so just read the code below.</p>
<blockquote><p><em>  class QueryBuilder {</em><em> 	</em></p>
<p><em>   const FIND_BY     = 'find_by';<br />
const FIND_ALL_BY = 'find_all_by';</em></p>
<p><em>   // field separator ( must comply with preg compatible regex )<br />
const SEPARATOR = '/(_and_|_or_)/';</em></p>
<p><em>   /**<br />
* This method will build a query depending on the statement and parameters passed<br />
*<br />
* @param string mock statement<br />
* @param array parameters for the query<br />
* @return array<br />
*    array[0] = string the sql that was generated<br />
*    array[1] = boolean true if a single row will be returned (find_by), otherwise false<br />
*/<br />
public static function getQuery($table, $statement, $parameters) {</em></p>
<p><em>	  $isSingle   = strpos($statement, self::FIND_BY);<br />
$isMultiple = strpos($statement, self::FIND_ALL_BY);</em></p>
<p><em>	  // check if the query passed is valid<br />
if($isSingle === false &amp;&amp; $isMultiple === false)<br />
throw new Exception("Method not found: " . $statement . '(' . implode(', ', $parameters) . ')');</em></p>
<p><em>	  // 1 is added for the simple reason of the statements having and extra  underscore[_] in the end (<br />
$startLength = 1 + ($isSingle !== false<br />
? strlen(self::FIND_BY)<br />
: strlen(self::FIND_ALL_BY));</em></p>
<p><em>	  $sql = self::constructQuery($table, substr($statement, $startLength), $parameters);</em></p>
<p><em>	  return array($sql, $isSingle !== false ? true : false);<br />
}</em></p>
<p><em>   private static function constructQuery($table, $statement, $parameters) {			</em></p>
<p><em>		//extract columns from statement by splitting the statement passed with the defined separators<br />
$columns = preg_split(self::SEPARATOR, $statement);<br />
if(count($columns) !== count($parameters))<br />
throw new Exception('Invalid number of parameters passed.');</em></p>
<p><em>		// store separators in separators array<br />
$separators = array();<br />
preg_match_all(self::SEPARATOR, $statement, $separators); </em></p>
<p><em>		// make separators valid by replacing all underscores from start and end of separator with nothing<br />
// note that &amp; on $v, this is needed so that reference of $v or actual value of $v will be changed<br />
foreach($separators as $k=&gt;&amp;$v) {<br />
$v = str_replace('_', '', $v);<br />
}</em></p>
<p><em>		// our sql stamenet would have the 1 = 1 at the end so we need another AND to concatenate the base statement below<br />
// with our column =&gt; value array defined ( the $where array )and glue them together with our separators ( $separators )<br />
array_unshift($separators[0], 'AND');</em></p>
<p><em>		// our base sql statement<br />
$sql = sprintf('SELECT * FROM %s WHERE 1=1 ' , $table);</em></p>
<p><em>		// loop for our where clause and append the separator, column name and parameter to our statement<br />
$length = count($columns);<br />
for($i = 0; $i &lt; $length; $i++) {<br />
$sql .= sprintf("%s %s = '%s' ", strtoupper($separators[0][$i]), $columns[$i], $parameters[$i] );<br />
}</em></p>
<p><em>		//trim down the sql generated<br />
return trim($sql);<br />
}<br />
}</em></p>
<p><em> ?&gt;</em></p></blockquote>
<p>The code can be extended to have a dynamic counter (SELECT COUNT(*)), finding with array values (Model.find_all_by_first_name(array('ronald', 'dohdoh'))), or even use camel casing (Model.findAllByUsername('dohdoh')).</p>
<p>You can download the codes below containing 3 files.<br />
- QueryBuilder.php -&gt; the query builder class above<br />
- TestTable.php -&gt; test model to be used in our unit test<br />
- QBTest.php -&gt; our unit test class, SimpleTest framework is required to run the this code</p>
<p><a TITLE="Creating a dynamic finder with PHP Files" HREF="http://www.dohdoh.net/wp-content/uploads/2008/01/dynamic-finder-with-php.zip">Creating a dynamic finder with PHP Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2008/01/08/creating-a-dynamic-finder-with-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Everywhere! December 1, 2007</title>
		<link>http://www.dohdoh.net/2007/10/15/php-everywhere-december-1-2007/</link>
		<comments>http://www.dohdoh.net/2007/10/15/php-everywhere-december-1-2007/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 06:42:58 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

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

		<guid isPermaLink="false">http://www.dohdoh.net/2007/10/15/php-everywhere-december-1-2007/</guid>
		<description><![CDATA[
PHP Everywhere! December 1, 2007
PHP User Group Philippines, Inc. (PHPUGPH), a non-profit organization established to provide support for LAMP (Linux Apache MySQL PHP) and open-source enthusiasts in the Philippines, will be holding it’s 1st ever PHP Developer’s Conference on December 1, 2007 (1-day event)/9am-6pm.
This is in follow-up with last Aprils successful event, a gathering of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://i2.photobucket.com/albums/y6/Garrizaldy/banner-dec1.png" /></p>
<p><strong>PHP Everywhere! December 1, 2007</strong></p>
<p>PHP User Group Philippines, Inc. (PHPUGPH), a non-profit organization established to provide support for LAMP (Linux Apache MySQL PHP) and open-source enthusiasts in the Philippines, will be holding it’s 1st ever PHP Developer’s Conference on December 1, 2007 (1-day event)/9am-6pm.</p>
<p>This is in follow-up with last Aprils successful event, a gathering of professional LAMP developers, web freelancers and companies utilizing OSS (Open-Source Software) technologies for enterprise use. The goal for this upcoming conference is to spread the news of using OSS solutions such as Linux, Apache, MySQL, PHP and some Web 2.0 technologies in wider audiences such as universities and training institutions.</p>
<p>Many noted members of our group are certified and professionally affiliated with leading company in the industry such as Barclays, UN-IOSN, Yahoo! Singapore, Accenture, Mobius Asia and some semi-conductor/electronics like Intel, Atmel, Amis, which has some open source software deployed in production environment.</p>
<p>Last Aprils event was sponsored as listed below that capture’s local IT industry attention and it is our aim to widen the coverage this coming December’s event with your support.</p>
<p>Previous Sponsors:</p>
<p>Zend Technologies<br />
<a href="http://www.zend.com" target="_blank">http://www.zend.com</a></p>
<p>Bandwagon<br />
<a href="http://www.ridethebandwagon.com" target="_blank">http://www.ridethebandwagon.com</a></p>
<p>Digital Media Exchange<br />
<a href="http://www.dmii.net" target="_blank">http://www.dmii.net</a></p>
<p>Eskwela<br />
<a href="http://www.eskwela.com" target="_blank">http://www.eskwela.com</a></p>
<p>HotelDealsAndMore<br />
<a href="http://www.hoteldealsandmore.com" target="_blank">http://www.hoteldealsandmore.com</a></p>
<p>Hostking<br />
<a href="http://www.hostking.ph" target="_blank">http://www.hostking.ph</a></p>
<p>Mobius Games Asia<br />
<a href="http://www.mobiusgames.net" target="_blank">http://www.mobiusgames.net</a></p>
<p>NeverFuget<br />
<a href="http://www.neverfuget.com" target="_blank">http://www.neverfuget.com</a></p>
<p>TechHive<br />
<a href="http://www.techhive.net" target="_blank">http://www.techhive.net</a></p>
<p>XackMail<br />
<a href="http://www.xackmail.com" target="_blank">http://www.xackmail.com</a></p>
<p>Ascendant Technologies<br />
<a href="http://www.ascendant.com.ph" target="_blank">http://www.ascendant.com.ph</a></p>
<p>Last event photos can be found at <a href="http://www.phpugph.com/eb" target="_blank">http://www.phpugph.com/eb</a><br />
Monthly meeting held last September 29, 2007 can be found at <a href="http://picasaweb.google.com/ajbatac/PHPUGPHInterimGroupMeetingSept29Saturday" target="_blank">http://picasaweb.google.c...roupMeetingSept29Saturday</a></p>
<p>Below are some universities that already showed interest and we’re hoping that your humble sponsorship either in package/s or in kind will bring more success in this event.<br />
UST<br />
<a href="http://www.ust.edu.ph" target="_blank">http://www.ust.edu.ph</a></p>
<p>UP<br />
<a href="http://www.upm.edu.ph" target="_blank">http://www.upm.edu.ph</a><br />
<a href="http://www.up.edu.ph" target="_blank">http://www.up.edu.ph</a></p>
<p>Ateneo<br />
<a href="http://www.admu.edu.ph" target="_blank">http://www.admu.edu.ph</a></p>
<p>Mapua<br />
<a href="http://www.mapua.edu.ph" target="_blank">http://www.mapua.edu.ph</a></p>
<p>TUP<br />
<a href="http://www.tup.edu.ph" target="_blank">http://www.tup.edu.ph</a><br />
The group has already lined up some of our local IT industry leaders as speakers covering various topics ranging from MySQL Enterprise Database, advance web-scripting using PHP, Web 2.0 and some IT technology business matters.</p>
<p>Also, some new sponsors/groups shows support as listed below and we’re looking forward that your name/company will be listed as well.</p>
<p>Our growing new sponsors:</p>
<p>EmuraSoft<br />
<a href="http://www.emeditor.com" target="_blank">http://www.emeditor.com</a><br />
Utraedit<br />
<a href="http://www.idmcomp.com" target="_blank">http://www.idmcomp.com</a></p>
<p>TheDesignPeople<br />
<a href="http://www.thedesignpeople.com" target="_blank">http://www.thedesignpeople.com</a></p>
<p>Offshoring<br />
<a href="http://www.offshoring.com" target="_blank">http://www.offshoring.com</a></p>
<p>Techhive<br />
<a href="http://www.techhive.net" target="_blank">http://www.techhive.net</a></p>
<p>Tentative Topics/Sessions this year:</p>
<p>1. CodeIgniter with Aptana (PHP) by Roger Filomeno (Mobile Specialist, TechBiz Asia Group Pte Ltd)<br />
2. TipidPC: How it was made! (PHP) by Jesus Domingo (Frontend Engineer, Yahoo! Singapore)***<br />
3. Database 101 using MySQL (Database) by Cherrie Anne Domingo (Multinational Investment Bank Corporation)<br />
4. Sulit:Ads made Easy (Business) by RJ David (CEO, Sulit.com.ph)<br />
5. Defensive Design (Web Design) by AJ Batac (Director of Operations, Webcore Canada)***<br />
6. CSS and the Web (Web Design) by Angela Sabas (Frontend Engineer, Yahoo! Singapore)***<br />
7. Test Driven Development in PHP:Recap (PHP) by Andre John Cruz (Application Developer, Barclays Singapore)***<br />
8. IT Trends (Business) by JR Yap (CIO, MobileXchange)<br />
9. Zend Core and Oracle (Database) by Clodelio Delfino (System Analyst, AMIS Asia)<br />
10. PHP in Schools: A Visit (PHP) by Anne Michelle Santos (Web Developer/Professor, University of Santo Tomas)<br />
11. Exploring OpenSUSE 10.3 (Linux) by Reuben Ravago (CEO, OLM Technologies)<br />
12. Medical Systems with PHP by Sergio Arroyo (President, Ascendant Technologies)<br />
13. Stealth Startup Product Launch by AJ Batac (Director of Operations, Webcore Canada)***</p>
<p>NEW SPEAKERS/SESSIONS WILL BE INVITED…</p>
<p>*** Pre-recorded sessions (possible online Q &amp; A during the event since some of the members are in other countries).</p>
<p>Below are some data of the group for your additional references:<br />
Name: PHP User Group Philippines Inc.<br />
Founded: January 2001<br />
Founder: AJ Batac (CEO)<br />
President: Clodelio Delfino, ZCE (System Analyst)<br />
Vice-President: Cherrie Ann Domingo (Software Developer)<br />
Treasurer: Anne Michelle Santos (Web Developer/Professor)<br />
Secretary: Garrizaldy Santos (Software Engineer)<br />
Incorporators:<br />
Jonathan Richie Yap (CIO)<br />
Ronald John David (CEO)<br />
Mark Edward Tan (Web Developer)<br />
Bryan Blas (Web Developer)<br />
Erwin Atuli (Software Engineer)<br />
Redelyn Villamin (Software Engineer)<br />
Current Forum Members: 1,130+<br />
Generates a monthly pageviews of almost half million</p>
<p>In return for your support…<br />
1) Inclusion of Logo and Link to PHPUGPH.com home (from December 2007 – to December 2008)<br />
2) Monthly email blast to all PHPUGPH members for 1 year (from Dec 2007 – to Dec 2008)<br />
3) Company logo to be included in the member’s tshirt</p>
<p>Source: <a href="http://www.phpugph.com" target="_blank">http://www.phpugph.com </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2007/10/15/php-everywhere-december-1-2007/feed/</wfw:commentRss>
		</item>
		<item>
		<title>BDD or TDD?</title>
		<link>http://www.dohdoh.net/2007/09/24/bdd-or-tdd/</link>
		<comments>http://www.dohdoh.net/2007/09/24/bdd-or-tdd/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 14:06:56 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[TDD]]></category>

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

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

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

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

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

		<category><![CDATA[Ruby on Rails]]></category>

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

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

		<guid isPermaLink="false">http://www.dohdoh.net/2007/09/24/bdd-or-tdd/</guid>
		<description><![CDATA[I've been reading Test Driven Development (TDD) and Behavior Driven Development (BDD) articles these past few days and I'm a little bit confused on their differences. I came across BDD when I'm taking a look at RSpec framework for Ruby.
According to the definition of BDD from wikipedia:
Behavior Driven Development (or BDD) is a software development [...]]]></description>
			<content:encoded><![CDATA[<p>I've been reading Test Driven Development (TDD) and Behavior Driven Development (BDD) articles these past few days and I'm a little bit confused on their differences. I came across BDD when I'm taking a look at <a href="http://rspec.rubyforge.org/" target="_blank">RSpec framework</a> for Ruby.</p>
<p>According to the definition of BDD from wikipedia:</p>
<blockquote><p><strong>Behavior Driven Development</strong> (or <strong>BDD</strong>) is a software development technique that questions the behavior of an application before and during the development process. Created in response to the failings the founders perceived in Test Driven Development, Behavior Driven Development addresses requirements and specification in a way that is more textual than its predecessor. By asking questions such as "What should this application do?" or "What should this part do?" developers can identify gaps in their understanding of the problem domain and talk to their peers or domain experts to find the answers. By focusing on the behavior of applications, developers try to create a common language that's shared by all stakeholders: management, users, developers, project management and domain experts.</p></blockquote>
<p>From what I understand, BDD is different from TDD on how they approach in 'testing' a unit/entity. TDD is more focused on the application logic, while BDD is focused on what the behavior of the application on a given situation.</p>
<p>I'll try to put some codes differentiating TDD and BDD approach on my next post.</p>
<p>Till next time. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dohdoh.net/2007/09/24/bdd-or-tdd/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Eclipse PDT 1.0</title>
		<link>http://www.dohdoh.net/2007/09/18/eclipse-pdt-10/</link>
		<comments>http://www.dohdoh.net/2007/09/18/eclipse-pdt-10/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 03:28:03 +0000</pubDate>
		<dc:creator>Ronald de Leon</dc:creator>
		
		<category><![CDATA[IDE]]></category>

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

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

		<guid isPermaLink="false">http://www.dohdoh.n