<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>maSnun&#039;s logs &#187; orchid</title>
	<atom:link href="http://masnun.com/blog/tag/orchid/feed/" rel="self" type="application/rss+xml" />
	<link>http://masnun.com/blog</link>
	<description>Personal Blog of maSnun</description>
	<lastBuildDate>Sat, 24 Jul 2010 04:33:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A beginner&#039;s look into the Orchid Models</title>
		<link>http://masnun.com/blog/2009/09/17/a-beginners-look-into-the-orchid-models/</link>
		<comments>http://masnun.com/blog/2009/09/17/a-beginners-look-into-the-orchid-models/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 17:22:57 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[orchid]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=629</guid>
		<description><![CDATA[In Orchid you must have the database setup and configured to use a model based on the tables of that database. The cool thing is that, you can use the tables of a database directly without explicitly constructing any models &#8230; <a href="http://masnun.com/blog/2009/09/17/a-beginners-look-into-the-orchid-models/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In Orchid you must have the database setup and configured to use a model based on the tables of that database. The cool thing is that, you can use the tables of a database directly without explicitly constructing any models with them. Make sure that you have configured your database connection correctly in &#8220;app/config/configs.php&#8221;. For each table in the defined database, you can use models like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table_name</span><span style="color: #339933;">;</span></pre></div></div>

<p>To find a specific entry, use the find() method of the model object. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id='10'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// find the entry with ID 10</span></pre></div></div>

<p>Remember that the columns are returned as associative arrays or dictionaries. To get the email address of the data marked by ID 10, we use:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Though I believe that it&#8217;d have been better if the resultset was an object as well. Then we would have been able to grab the email address by typing:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #666666; font-style: italic;">// This is not possible yet</span></pre></div></div>

<p>I have an work around it. Just cast the resultset into an object using this following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Now it works :)</span></pre></div></div>

<p>Well, having an associative array is not bad, but it&#8217;s cooler to have an object <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you are obsessed about OOP, take the advantage of the model class definition and override the find() method to return an object.</p>
<p>Suppose we have a table named &#8220;users&#8221; which we will convert into a model. Go to the &#8220;app/models&#8221; directory and save the following file as: usersmodel.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> usersmodel <span style="color: #000000; font-weight: bold;">extends</span> activemodel <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> find<span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// call the parent class's find() method</span>
		<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #000088;">$res</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// cast the array into an object</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$res</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// return the object</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now you are done <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  You can now use the &#8220;users&#8221; model as following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id='2'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">;</span></pre></div></div>

<p>Cool, isn&#8217;t it ? Orchid is really fantastic when it comes to flexibility. I love it ! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><b>Methods:</b></p>
<p>Once you have retrieved or constructed a resultset, you can use the following methods to interact with the database:</p>
<p>clean() &#8212; Cleans all values of a model&#8217;s fields.<br />
delete() &#8212; Delete the row that contains the current resultset.<br />
insert() &#8212; Once you have added values to each of the fields, use this method to insert the data.<br />
update() &#8212; Updates the resultset with altered data.<br />
find() &#8212; Finds and returns a single resultset based on the given condition.<br />
findAll() &#8212; Finds all the results based on the condition.<br />
findById() &#8212; Finds a single resultset based on the &#8220;id&#8221; field.<br />
save() &#8212; Similar to update, it saves the resultset into the database.<br />
join() &#8212; For complex queries having &#8220;joining&#8221; operations.</p>
<p><b>PS:</b> There are lots more functionalities in Orchid models. Hasin vai taught me many of the fantastic features that the models in orchid have. But unfortunately, I have lost many of those information from my memory. I&#8217;ll have to check my chat history or ask Hasin bro again when I need those functionalities. But mainly these techniques described above would do most of my database related tasks.</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/09/17/a-beginners-look-into-the-orchid-models/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Orchid Experience</title>
		<link>http://masnun.com/blog/2009/09/17/the-orchid-experience/</link>
		<comments>http://masnun.com/blog/2009/09/17/the-orchid-experience/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 06:25:08 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[orchid]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=626</guid>
		<description><![CDATA[For our next project at Leevio, it has been decided that we will use Orchid as our PHP framework. It&#8217;s a framework created by Hasin Hayder, the founder of Leevio and the PHP Guru of Bangladesh. Today I was assigned &#8230; <a href="http://masnun.com/blog/2009/09/17/the-orchid-experience/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For our next project at Leevio, it has been decided that we will use Orchid as our PHP framework. It&#8217;s a framework created by Hasin Hayder, the founder of Leevio and the PHP Guru of Bangladesh. Today I was assigned to make myself used to this framework. I don&#8217;t have any prior experience of working with a fully fledged frameworks. So I was a bit worried. I checked out the Orchid framework codes from the Google Code SVN repo and installed the framework in my localhost. First I failed to make it work because by mistake I have left the .htaccess file which was hidden in my file explorer by default. Soon, I understood that I have left behind the lifeblood of a framework &#8212; the URL rewriting definition in the .htaccess file. I quickly pressed Ctrl + H to unhide the hidden files and copied the .htaccess file into my www/orchid directory. Whoa! I was now able to see the welcome page at http://localhost/orchid/. While I must admit that Hasin vai has a worse sense of what a welcome page should look like, on the other hand I must admit that the messy page took much of my tension away <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>I examined the sample apps for a while but since I have no prior experience in a whole framework like Orchid, I was having a tough time understanding how the wheel rotates inside Orchid. But I could ocassionaly make some educated guesses and my asking Hasin vai proved that all of them were correct <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I was now more comfortable at exploring this new Island that at first seemed to be so full of vicious creatures.</p>
<p>After a while, I realized that I am that sort of stupid who can&#8217;t understand theories until he has done some practical work. I decided to do something on my own. While browsing the source, I found a &#8220;cli.php&#8221; in the root directory of Orchid. Those who know me or have read enough of blogs, they&#8217;d know that I am badly fascinated by cli tools. Examining the cli.php file, I could figure out that this one creates skeleton codes for an app. The cli tool has two options &#8212; create a skeleton app or an app with pre-installed controller and views. I chose the second option.</p>
<p>First, I removed the samples those came bundled up with Orchid. Then I opened up my terminal and fired off typind the following codes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>masnun<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>orchid<span style="color: #000000; font-weight: bold;">/</span>
php cli.php controller masnun</pre></div></div>

<p>That&#8217;s all I needed. First one changed the current working directory to the Orchid directory. The second one invoked the Orchid CLI tool to create a controller for &#8220;masnun&#8221;. Again, I should criticize Hasin Vai, the CLI tool prints nothing but a single line saying &#8212; &#8220;Welcome to the CLI tool of Orchid&#8221; or something like that. Though it gives an error message on failure, I don&#8217;t think thats any credit of the tool in question, rather the error message is generated by PHP itself. On the other hand, on success, you get not even a single line congratulating you or at least saying &#8220;hi&#8221;. I am very much offended by such rudeness <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Anyway, I was now ready to view my app at: http://localhost/orchid/masnun/</p>
<p>It showed a simple text saying &#8220;Called from masnun/base method&#8221;. That made sense to me. There is a &#8220;base&#8221; method inside the &#8220;masnun&#8221; controller. I opened up the controller file and yeah, there really was a base method and another method named &#8220;hello&#8221; <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I was curious to see, what this other method does. So, I visited out of curiosity the following URL:</p>
<p>http://localhost/orchid/masnun/hello/</p>
<p>The result was somehow obvious, yeah it printed &#8220;hello world!&#8221;.</p>
<p>Now I came to think about it. How does Orchid work ? Well, I was feeling stupid now, since it has now been quite clear. The URL format is:</p>
<p>/controller/method.</p>
<p>If you just visit the controller, the base method is called. That is:</p>
<p>&#8220;/controller/&#8221;  == &#8220;/controller/base/&#8221;</p>
<p>It was easy as pie! Then I moved on to using templating. Opened up the view directory and found two files &#8212; &#8220;base.php&#8221; and &#8220;hello.php&#8221;. I had no doubt that they had markup for each of the method of the controller. I opened up the controller again to examine.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;masnun&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Aha&#8230; I don&#8217;t even have to explicitly define the view ? Cool&#8230; Hasin vai really has some talent then <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Every method auto loads the curresponding view <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  That cuts down the work of a programmer for sure. But wait! How can Hasin vai be this stupid ? What if I need to setup a different view ? Oh my god! I have to tell him about this.</p>
<p>I was frustrated with Orchid and closed the current working copies and started examining the sample apps. At that time, I realized that Hasin vai was not stupid at all, he&#8217;s a genius ! He does have the &#8220;setView()&#8221; method. I was relieved and feeling sorry for cursing the gentleman for a while. But still, I would defend myself because if Hasin vai had a good documentation, I would have known it long before and didn&#8217;t need to curse him at all. So, you see? It&#8217;s his fault after all and he does deserve some curses for not having a total documentation. What do you say ? <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I immediately used the following code in the hello method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setView</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;base&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;masnun&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Wow ! It does work. I have been able to reproduce the base method view just by changing the view of the hello method. I am damn happy.</p>
<p>Later I found out that, there&#8217;s a &#8220;layouts&#8221; folder inside the &#8220;views&#8221; directory where I can define the global layout for a controller. I created a &#8220;masnun.php&#8221; in the layouts directory and put these code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Orchid&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$layoutdata</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Cool ! The template was applied to the whole controller &#8212; that is to both the base and hello method.</p>
<p>I am just loving this framework! Orchid has some cool built in libraries for additional features. Have a look at it&#8217;s core features:</p>
<p>1. Support for Caching<br />
	a. SQLite Based Caching<br />
	b. MySQL Caching<br />
	c. Memcached Caching</p>
<p>2. Built in Unit Testing Support<br />
3. Fast and Lightweight<br />
4. Support for MySQL, MySQLi, SQLite, MSSQL and PgSQL using Native DAL and PDO<br />
5. Support for Layout<br />
6. Active Record<br />
7. Easy Application Setup<br />
8. Flexible Configuration Management<br />
9. Builtin Profiling<br />
10. I18N support<br />
11. Session Manager (Native and DB Based)<br />
12. Excellent support for benchmarking and profiling<br />
13. Builtin JSON Encoder and Decoder<br />
14. Google Chart API Support<br />
15. Bundled JS Libraries with Gzip Support<br />
	a. Prototype<br />
	b. JQuery<br />
	c. SWFObject<br />
16. Builtin Library for jQuery Effects and AJAX Support</p>
<p><b>PS:</b> I am still learning Orchid and hope to keep posted about my progress. I am now concentrating on understanding the models system of Orchid <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  A big thanks to Hasin vai for this wondeful framework !</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/09/17/the-orchid-experience/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
