<?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; framework</title>
	<atom:link href="http://masnun.com/blog/tag/framework/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>Coupling Zend Framework with CodeIgniter</title>
		<link>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/</link>
		<comments>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 11:48:13 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=959</guid>
		<description><![CDATA[CodeIgniter is a super cool web application framework for PHP. It is lightweight and lets you get the jobs done in a fashion. It is the first framework I have used and I am still using it. On the other &#8230; <a href="http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter is a super cool web application framework for PHP. It is lightweight and lets you get the jobs done in a fashion. It is the first framework I have used and I am still using it. On the other hand, Zend Framework is from Zend, the PHP company. I appreciate the huge library and the full stack nature. I respect the fact that ZF is from the people who maintain PHP. But honestly, I don&#8217;t find it feasible for medium and small projects. </p>
<p>One of the brighter aspects of the Zend Framework is that it has many cool libraries. The framework itself is loosely tied and the components are available as stand alone. We can take this opportunity to integrate the powerful library of the Zend Framework into the beautiful CodeIgniter making ourselves more productive than before. Specially, we can relieve ourselves from writing and maintaining wrappers to different APIs.</p>
<p>Ok then, let&#8217;s see how do we integrate the Zend Framework libraries into CI.</p>
<p>1) Setup CodeIgniter.</p>
<p>2) Download the Zend Framework. Extract the archive. </p>
<p>3) From the ZF files, copy the &#8220;Zend&#8221; directory from inside the &#8220;library&#8221; directory.</p>
<p>4) Paste the directory into the &#8220;system/application/libraries&#8221; directory. So ultimately, the new location of the copied &#8220;Zend&#8221; directory would be &#8220;system/application/libraries/Zend&#8221;. If you&#8217;re on Linux/Unix, we need to deal with file permission. Make the Zend directory accessible by all. I don&#8217;t think I need to tell you how to do that with chmod, do I ? <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>5) In the same  &#8220;system/application/libraries/&#8221; directory, create a new file named &#8220;Zend.php&#8221; and put the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Zend
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> APPPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$class</span> <span style="color: #339933;">.</span> EXT<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We are done. That completes the integration. Now we can load any Zend component inside our controllers. Let&#8217;s make our hands dirty by modifying the default welcome controller. Open the &#8220;system/application/controllers/welcome.php&#8221; and put the following contents:</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> Welcome <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Welcome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zend'</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;">zend</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend/Service/Flickr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$flickr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Service_Flickr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'12e99caebb8f305fff5a943606ecde18'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tagSearch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'worldcup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
                      <span style="color: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Small</span><span style="color: #339933;">;</span>
                      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$photo-&gt;clickUri}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$photo-&gt;uri}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you read the codes above, you already know what it does <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If everything goes right, you&#8217;ll see a bunch of Flickr photos with the &#8220;worldcup&#8221; tag. Clicking on a photo will take you to the Flickr page of that photo.</p>
<p>Now, what we have seen is pretty straightforward. We don&#8217;t use any hooks or don&#8217;t go for any complexity. We simply put the Zend library in the application library. Then we write a loader class that loads Zend libraries. When we construct this &#8220;Zend Loader&#8221; object, it adds the Zend library directory to the include path. Then when we use the load() method of the object, it imports the library and adds the functionalities to the current scope <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enjoy the Zend Services with the cool CodeIgniter framework! Have fun <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Code Completion with the Netbeans IDE for PHP</title>
		<link>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/</link>
		<comments>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 06:38:51 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=953</guid>
		<description><![CDATA[CodeIgniter is my favorite web application framework for PHP and Netbeans is the IDE I use for all sorts of web development. The latest version of Netbeans IDE (6.9) has support for both Symfony and Zend Framework. But it still &#8230; <a href="http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter is my favorite web application framework for PHP and Netbeans is the IDE I use for all sorts of web development. The latest version of Netbeans IDE (6.9) has support for both Symfony and Zend Framework. But it still has no official support for CodeIgniter. So, in the default installation, you will always miss the fantastic code completion feature of the IDE.</p>
<p>After Googling a while, I just learned a magic trick that can emulate this feature in Netbeans. The process is pretty simple. We feed Netbeans a php file that has a simple sample &#8220;Controller&#8221; class definition that has phpdoc specifying the necessary properties. We put this file in a place readable by the IDE by invisible or worthless for the CodeIgniter framework. The &#8220;nbproject&#8221; directory inside the project root could be a good place to put this file. What really happens is that Netbeans reads the phpdoc and offers the completion of the specified properties in any class that extends the Controller class. Hiding it from CodeIgniter helps not to mess up with the system.</p>
<p>This is what I did. I created a php file and named it &#8220;nb.php&#8221;. I filled this file with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Table $table
* @property CI_Session $session
* @property CI_FTP $ftp
* ....
*/</span>
<span style="color: #000000; font-weight: bold;">Class</span> Controller <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And put the file inside my nbproject directory. Now I am getting code completion in my Netbeans for CodeIgniter. </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<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>
		<item>
		<title>Query String support Added to MWF</title>
		<link>http://masnun.com/blog/2009/09/11/query-string-support-added-to-mwf/</link>
		<comments>http://masnun.com/blog/2009/09/11/query-string-support-added-to-mwf/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 05:27:18 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=601</guid>
		<description><![CDATA[Here it comes &#8212; An important update for MWF. Now you can use $_GET and $_POST data without any problem. I have noticed that since I used &#8220;url&#8221; as an internal variable in the framework engine, it&#8217;d mess up if &#8230; <a href="http://masnun.com/blog/2009/09/11/query-string-support-added-to-mwf/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here it comes &#8212; An important update for MWF. Now you can use $_GET and $_POST data without any problem.</p>
<p>I have noticed that since I used &#8220;url&#8221; as an internal variable in the framework engine, it&#8217;d mess up if someone used &#8220;url&#8221; in the GET method. So I changed the internal code to replace &#8220;url&#8221; with something very cryptic and now I believe that you can use the framework without any hassle.</p>
<p>Still, if you find some sort of bugs or have some suggestions, please let me know,</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/09/11/query-string-support-added-to-mwf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MWF Reborn</title>
		<link>http://masnun.com/blog/2009/09/09/mwf-reborn/</link>
		<comments>http://masnun.com/blog/2009/09/09/mwf-reborn/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:28:26 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=596</guid>
		<description><![CDATA[I have been enough bored when I finally decided to rewrite the MWF from the scratch. I wrote this webapp framework and named &#8220;Masnun&#8217;s Webapp Framework&#8221; weeks ago. Gradually I forgot about it like many of my other projects I &#8230; <a href="http://masnun.com/blog/2009/09/09/mwf-reborn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been enough bored when I finally decided to rewrite the MWF from the scratch. I wrote this webapp framework and named &#8220;Masnun&#8217;s Webapp Framework&#8221; weeks ago. Gradually I forgot about it like many of my other projects I didn&#8217;t get the time to complete. But I needed a webapp framework pretty badly for the ongoing free lance projects at hand. The buyers hire me for doing the programming part and create the HTML templates by other professional designers. Then I have to merge my program into the HTML. It&#8217;s a pain if I don&#8217;t use some sort of templating engine. Again, I want the URLs to look professional and structured. To meet these needs, I had to go for a web application framework. I liked the web.py framework for Python but most of my clients want me to use PHP. I have tried CodeIgniter and Smarty. But they are huge in overhead and feature packed. I don&#8217;t really need half the features they provide.</p>
<p>Keeping all these in head, I started re-writing the MWF from scratch. This time I have managed to build a fully functional URL router that is smart enough to support regular expression. I have also managed to create a templating system for it. Though it&#8217;s nothing cool if you compare to the popular frameworks, it does serve my purpose.</p>
<p>I have included a MIT license in this release and uploaded it to my google code repository for downloads.</p>
<p><strong>Download: </strong> <a href="http://masnun.googlecode.com/files/mwf.zip">http://masnun.googlecode.com/files/mwf.zip</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>How to use it?</strong><br />
Using it is quite simple. You&#8217;ll find a demo inside the downloaded package.</p>
<p>It doesn&#8217;t have any models. Just URL routing and templating for now.</p>
<p>&#8211; First include the library.<br />
&#8211; Map the URLs to callback functions. These URLs are matched using regex and if matches the path is sent to the callback function as the only parameter. We define the URL routes as comma separated pairs. I could use a dictionary but I liked this way. I have found it fun while exploring web.py. First the URL pattern, then the callback function for it, then another pattern and it&#8217;s call back function, another pair in this way and it goes on&#8230; <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8211; Start the web app.</p>
<p>&#8211; Define the callback functions.</p>
<p><strong>Sample</strong></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: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mwf.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// include the library</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// route the urls. first the url, then the callback function name</span>
<span style="color: #666666; font-style: italic;">// url pattern supports regex</span>
<span style="color: #666666; font-style: italic;">// matched url will be sent to the  callback function as the only parameter</span>
&nbsp;
<span style="color: #000088;">$urls</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/masnun&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;redir&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;/tag/[\w]+&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// done. run the webapp</span>
mwf_run<span style="color: #009900;">&#40;</span><span style="color: #000088;">$urls</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define the callback functions which work as controllers</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> home<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/*
&nbsp;
To render a template, feed the function with a php file
and an associative array of key-value pairs (dictionary)
&nbsp;
 */</span>
template_render<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'views/layout.php'</span><span style="color: #339933;">,</span><span style="color: #000088;">$dic</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tag&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> redir<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Use the mwf_redirect() function for url redirection</span>
mwf_redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/tag/home&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>That&#8217;s it&#8230; Quite simple&#8230; <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/09/09/mwf-reborn/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NiceDog PHP Framework</title>
		<link>http://masnun.com/blog/2009/09/08/nicedog-php-framework/</link>
		<comments>http://masnun.com/blog/2009/09/08/nicedog-php-framework/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 14:52:17 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=585</guid>
		<description><![CDATA[I was looking for a web.py like PHP framework for a long time. And looks like finally I have found one. It&#8217;s called &#8220;NiceDog&#8221; and it&#8217;s really cool. Download Link: http://masnun.googlecode.com/files/nicedog.zip I found the official website down and then retrieved &#8230; <a href="http://masnun.com/blog/2009/09/08/nicedog-php-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was looking for a web.py like PHP framework for a long time. And looks like finally I have found one. It&#8217;s called &#8220;NiceDog&#8221; and it&#8217;s really cool.</p>
<p><strong>Download Link:</strong> <a href="http://masnun.googlecode.com/files/nicedog.zip">http://masnun.googlecode.com/files/nicedog.zip</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I found the official website down and then retrieved the cached copy of the website from Google. There I found the project link to GitHub and managed to download a copy of the framework. The features are really good except that the template rendering system was a bit weird and I could not make it work. So I hacked the core and fixed things to suit my way. It just works fine for now though I had to get rid of &#8220;base template&#8221; functionality.</p>
<p>Since I liked the framework, I uploaded a copy of the modified version to my google code repository.</p>
<p><strong>How to work with it ?</strong></p>
<p>The following code adds the regex to catch URL in the format:</p>
<p>http://localhost/tag/anytext/</p>
<p>And calls the &#8216;index&#8217; method of &#8216;Test&#8217; object if the HTTP request was GET.<br />
Quite like web.py, isn&#8217;t it ?<br />
The Controller class, in this case, the Test class should always extend the built in class &#8220;C&#8221;.</p>
<p>To use template, just use render() method of the object. It&#8217;d pass all the variables defined under the object to that file. You just need to echo the variables in the target template file.</p>
<p>The framework has no &#8220;models&#8221;. So it&#8217;s not a MVC. But since it&#8217;s based on PHP, we can do without any models, handcrafting the database oriented codes.</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: #b1b100;">require</span> <span style="color: #0000ff;">'NiceDog.php'</span><span style="color: #339933;">;</span>
R<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag/(?P&lt;tag&gt;[-\w]+)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">on</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GET'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #000000; font-weight: bold;">extends</span> C<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'views/layout.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Source of the template file:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
&lt;h1&gt;My firs example&lt;/h1&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Conclusion:</strong> NiceDog is not a fully fledged framework. It&#8217;s in fact a nano PHP framework for small projects that require less features and small over head.</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/09/08/nicedog-php-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using web.py with Google App Engine</title>
		<link>http://masnun.com/blog/2009/08/01/using-web-py-with-google-app-engine/</link>
		<comments>http://masnun.com/blog/2009/08/01/using-web-py-with-google-app-engine/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 03:15:12 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[free-services]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=382</guid>
		<description><![CDATA[I love coding in Python and have been exploring the excellent web.py framework lately. From what I&#8217;ve seen, web.py is a very simple yet powerful python based web framework. It&#8217;d take me a lot of time to learn django (if &#8230; <a href="http://masnun.com/blog/2009/08/01/using-web-py-with-google-app-engine/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I love coding in Python and have been exploring the excellent web.py framework lately. From what I&#8217;ve seen, web.py is a very simple yet powerful python based web framework. It&#8217;d take me a lot of time to learn django (if I ever manage to make up my mind into it) and it already took around a couple of hours to understand the Google App Engine&#8217;s default webapp framework.</p>
<p>web.py includes a built in web server to develop an application locally. But I am a Google fan and was thinking of deploying web.py on Google App Engine. I believed GAE and web.py together can help me put up a web app in minutes. And so did they&#8230; <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>The first question came to my mind was &#8220;How am I going to install web.py on my GAE account ?&#8221;. Well, it was pretty easy in the end. Just extract the web.py package and put the &#8220;web&#8221; directory inside your application directory. That is the &#8220;web&#8221; directory would be in the same directory where the app.yaml file resides. Now, in app.yaml file, map all URLs to a single python file. In my case, it was &#8220;main.py&#8221;.</p>
<p>Now develop the application in the normal web.py way. &#8220;It&#8217;s easy as pie!&#8221; &#8212; I thought. But it was not that easy in fact. I had to make a couple of changes.</p>
<p>The app I wrote didn&#8217;t do what I expected it to. Rather it raised an &#8220;import error&#8221; <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Later, I found out that I have to use &#8220;web.application.cgirun()&#8221; method instead of the normal &#8220;run()&#8221; method.</p>
<p>Then I reloaded the app. But this time I got an &#8220;internal server error&#8221;. After visiting the web.py cookbook, I found out that, to use web.py templates on GAE, I have to compile all templates using the &#8220;web/template.py &#8211;compile templates&#8221; command. I did so. All my templates were compiled into python source code. Cool !</p>
<p>Now my app was running smooth and working fine ! So, at last I made it&#8230; Yahoo ! I am loving python, web.py and Google App Engine together <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>PS: I am using web.py 0.3 where I have the cgirun() method. In older versions of web.py, you have to be tricky. In that case, please consult this thread:</p>
<p><a href="http://bit.ly/EoVyM" target="_blank">http://bit.ly/EoVyM</a></p>
<p><strong>Here&#8217;s the source code (Without the template):</strong></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> web
urls = <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/(.*)&quot;</span>,<span style="color: #483d8b;">&quot;site&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> <span style="color: #dc143c;">site</span>:
	<span style="color: #ff7700;font-weight:bold;">def</span> GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,path<span style="color: black;">&#41;</span>:
		render = web.<span style="color: black;">template</span>.<span style="color: black;">render</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'templates'</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> render.<span style="color: black;">masnun</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>
&nbsp;
app = web.<span style="color: black;">application</span><span style="color: black;">&#40;</span>urls,<span style="color: #008000;">globals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	app.<span style="color: black;">cgirun</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
  main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>Here&#8217;s the &#8220;templates/masnun.htm&#8221;:</strong></p>
<pre>$def with (name)
&lt;html&gt;&lt;head&gt;&lt;title&gt;web.py demo&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
You requested: &lt;b&gt; $name&lt;/b&gt;&lt;/body&gt;&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/08/01/using-web-py-with-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Sub-applications on web.py</title>
		<link>http://masnun.com/blog/2009/07/19/using-sub-applications-on-web-py/</link>
		<comments>http://masnun.com/blog/2009/07/19/using-sub-applications-on-web-py/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 14:45:54 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/2009/07/19/using-sub-applications-on-web-py/</guid>
		<description><![CDATA[I have started learning the web.py framework for python. It&#8217;s simply a great framework. Here&#8217;s a code snippet I wrote a few minutes ago to try the sub-application feature of web.py. There is mainly two applications here à &#8220;app&#8221; and &#8230; <a href="http://masnun.com/blog/2009/07/19/using-sub-applications-on-web-py/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have started learning the web.py framework for python. It&#8217;s simply a great framework. Here&#8217;s a code snippet I wrote a few minutes ago to try the sub-application feature of web.py.
</p>
<p>There is mainly two applications here <span style="font-family:Wingdings">à</span> &#8220;app&#8221; and &#8220;viewapp&#8221;. The &#8220;app&#8221; application maps &#8220;/view&#8221; url to the &#8220;viewapp&#8221; application while the later handles any request passed to it [ "/(.*)" ] and prints out the requested url.
</p>
<p>This can be helpful for creating well structured URLs like http://localhost/view/1034 which will retrieve the article ID 1034 from the database.
</p>
<p>Here&#8217;s the code:<br/><br/></p>
<pre lang+"PYTHON">
<em>import web<br/>class view:<br/>    def GET(self,path):<br/>        return path<br/>urls2 = ("/(.*)","view")<br/>viewapp = web.application(urls2,globals())<br/>urls = ("/view",viewapp)<br/>app = web.application(urls,globals())<br/>if __name__ == "__main__":<br/>    app.run() </em></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/07/19/using-sub-applications-on-web-py/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MWF &#8212; Masnun&#039;s Web Framework</title>
		<link>http://masnun.com/blog/2009/04/21/mwf-masnun%e2%80%99s-web-framework/</link>
		<comments>http://masnun.com/blog/2009/04/21/mwf-masnun%e2%80%99s-web-framework/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 11:31:27 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/2009/04/21/mwf-masnun%e2%80%99s-web-framework/</guid>
		<description><![CDATA[I was a bit fascinated by the URL mapping techniques implemented by Google in GAE. I know most/all of the MVC php frameworks are going to support custom URL mapping. But I was looking for a simple one. And not &#8230; <a href="http://masnun.com/blog/2009/04/21/mwf-masnun%e2%80%99s-web-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was a bit fascinated by the URL mapping techniques implemented by Google in GAE. I know most/all of the MVC php frameworks are going to support custom URL mapping. But I was looking for a simple one. And not finding one that is exactly what I wanted, I wrote my own web framework <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />
</p>
<p>The project is still in beta and currently it can only map incoming requests. You need to build URIs as functions. Analyzing the incoming request, the framework calls the corresponding fuction.
</p>
<p><span style="font-size:10pt"><strong>&lt;?php<br/>include &#8220;mwf.php&#8221;;<br/>$webapp = new MWF();<br/>$url['/regex/'] = &#8220;home&#8221;;<br/>$webapp-&gt;map($url);<br/>?&gt;<br />
</strong></span></p>
<p><span style="font-size:10pt"><strong>&lt;?php function home() {?&gt;<br/>&lt;html&gt;<br/>&lt;head&gt;&lt;title&gt;&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;&lt;/title&gt;<br/>&lt;/head&gt;<br/>&lt;body&gt;&lt;b&gt;You requested:&lt;/b&gt; &lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;&lt;br /&gt;&lt;/body&gt;<br/>&lt;/html&gt;<br/>&lt;?php } ?&gt;<br />
</strong></span></p>
<p>In the above code snippets, we see MWF in action. Here, we instantiate the MWF. Map the &#8216;/regex/&#8217; URI to the &#8220;home&#8221; function. When a visitor requests the URL http://yoursite.com/regex/, the home() function will be called. In our example the function serves a HTML document. You can also generate other mark ups or simply put some HTTP responses yourself. But remember, the script can not recognize static files. In case of delivering a static file, you have to define it&#8217;s URI in the URL map and create a function that serves the file manually. I will give an example of that in a future post.
</p>
<p>The MWF class has a default notFound() method which handles any situations where the requested URI is not mapped. You may extend the class and modify this method to define your own 404 page or put some HTTP response.
</p>
<p>The URL map still doesn&#8217;t support regex. But if I get good response (I am not that convinced that I will get any), I will work on that as well.
</p>
<p>The .htaccess file is required and you must have .htaccess support enabled on your host for the framework to operate.
</p>
<p><strong>DOWNLOAD LINK:</strong> <a href="http://php.masnun.com/mwf.zip">http://php.masnun.com/mwf.zip</a>
</p>
</p>
<p><strong>Files Included:</strong>
	</p>
<ul>
<li>.htaccess (Apache HTACCESS Conf)
</li>
<li>mwf.php (Contains the MWF class)
</li>
<li>index.php (The Sample Application)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/04/21/mwf-masnun%e2%80%99s-web-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
