<?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>Conceptric &#187; trials</title>
	<atom:link href="http://www.conceptric.co.uk/tag/trials/feed" rel="self" type="application/rss+xml" />
	<link>http://www.conceptric.co.uk</link>
	<description>Ideas and Applications</description>
	<lastBuildDate>Mon, 15 Mar 2010 19:32:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code ignition</title>
		<link>http://www.conceptric.co.uk/code-ignition.htm</link>
		<comments>http://www.conceptric.co.uk/code-ignition.htm#comments</comments>
		<pubDate>Sun, 16 Nov 2008 12:53:11 +0000</pubDate>
		<dc:creator>James Whinfrey</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[Posts]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[trials]]></category>

		<guid isPermaLink="false">http://www.conceptric.co.uk/?p=111</guid>
		<description><![CDATA[Whilst developing a relatively simple application for managing my budgets, I've decided to experiment with a few different frameworks. With so many to choose from, how do I feel about going for CodeIgniter?]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter is billed as being a lightweight PHP <abbr title="Model - View - Controller">MVC</abbr> framework. Now I&#8217;m not a big fan of PHP, despite using WordPress and Drupal, but I intend to run this application on a Synology <abbr title="Network Attached Storage">NAS</abbr>, so PHP is the only game in town.</p>
<h3>Changing the Architecture.</h3>
<p>I&#8217;m not a keen on the idea of dumping all my code in the web server root directory, so I tested the framework flexibility by rearranged the application structure a little.</p>
<pre class="code">
	-rw-r--r--   1 Capfile
	drwxr-xr-x  14 application
	drwxr-xr-x   3 config
	drwxr-xr-x  13 system
	drwxr-xr-x   5 public
</pre>
<p>Once these locations were updated in the application configuration files it all worked perfectly. The reasons for doing this sort of thing have been <a href="http://capsizedesigns.com/blog/2008/06/getting-started-with-codeigniter-part-5-loose-ends/">documented elsewhere</a>, and I agreed with them from this security standpoint, however this structure also fits better with <a href="http://www.conceptric.co.uk/capistrano-works.htm">Capistrano deployment</a>.</p>
<h3>A positive first impression.</h3>
<p>The Views deal with the presentation logic, and I like the fact that embedding PHP within the HTML is the default, instead of a complex templating system. It&#8217;s not the cleanest approach, but I prefer to have full control over my HTML.</p>
<p>As for the Controllers, the implementation is quite intuitive and you can build a friendly set of URLs with a little help from <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite</a> and the <a href="http://codeigniter.com/user_guide/libraries/uri.html"><code>URI</code> class</a>. </p>
<p>The form validation is a great feature that I found easy to implement within the Controllers and Views. I&#8217;ve centralised my validation rules in the global configuration file <a href="http://codeigniter.com/user_guide/libraries/form_validation.html#savingtoconfig">suggested in the documentation</a>, but haven&#8217;t got the automatic rule group feature to work yet.</p>
<p>The <code>Model</code> class is used to represent a single database table. I&#8217;m used to mapping tables with a Class in this way, but normally each instance would represent a row of data. CodeIgniter <code>Models</code> implement the <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton design pattern</a>, only one instance per class, from which the <code>Database</code> class methods can be called.</p>
<p>The <code>Database</code> class provides the data access layer and a good set of robust methods which return an array of <code>stdClass</code> instances representing the resulting data rows. These arrays are then forwarded to the View, where the instance variables can be directly accessed. This is quick and easy, but not very <abbr title="Object Oriented Programming">OOP</abbr>.</p>
<h3>Implementation reservations.</h3>
<p>I believe that the Model should be capable of running as a stand-alone application, once equipped with any interface, even the command-line. It&#8217;s this level of autonomy that results from the MVC design pattern: substitute a different Controller and View and it&#8217;ll still work the same way on a different platform.</p>
<p>Controllers reacting to events, whilst Views shouldn&#8217;t have direct, mutable access to instance variables. The Model should encapsulate both the data and the business logic, not something that can be effectively achieved with Singletons alone. Indeed CodeIgniter blurs this distinction by making Models optional and allowing data manipulation directly in the Controllers.</p>
<p>I&#8217;ve implemented my preferred approach by providing my own classes to replace the <code>stdClass</code>. They don&#8217;t extend the CodeIgniter <code>Model</code> class, but are instantiated within those that do, encapsulating data and business logic; including Object&#8211;relational data mapping and <acronym title="Create - Read - Update - Delete">CRUD</acronym> functionality.</p>
<p>It works well, but I&#8217;m concerned that by introducing a more rigourous approach I&#8217;m losing some of the advantages of the framework. May be I would be better to take CodeIgniter at face value, as a flexible, if a little dirty, rapid development environment that works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptric.co.uk/code-ignition.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
