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

<channel>
	<title>Add It Up Development Blog &#187; CodeIgniter</title>
	<atom:link href="http://blog.letsadditup.com/category/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.letsadditup.com</link>
	<description>Building a PHP financial management app, one line of code at a time</description>
	<pubDate>Thu, 11 Dec 2008 12:50:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Controller, Model, and URL design</title>
		<link>http://blog.letsadditup.com/2008/08/08/controller-model-and-url-design/</link>
		<comments>http://blog.letsadditup.com/2008/08/08/controller-model-and-url-design/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 16:14:37 +0000</pubDate>
		<dc:creator>Matthew Pennell</dc:creator>
		
		<category><![CDATA[CodeIgniter]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://blog.letsadditup.com/?p=22</guid>
		<description><![CDATA[What&#8217;s in a name?
Like I would imagine many programmers, I have a tendency to get a little anal about naming my Controllers and Models. Combine this with the default behaviour of CodeIgniter to parse the URL segments into controller/function/id parts, and it all begins to get very messy unless some careful thought is put into [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s in a name?</p>
<p>Like I would imagine many programmers, I have a tendency to get a little anal about naming my Controllers and Models. Combine this with the default behaviour of CodeIgniter to parse the URL segments into controller/function/id parts, and it all begins to get very messy unless some careful thought is put into this stage of a project.</p>
<p>For my finance application there are a few obvious &#8216;pages&#8217; needed. A user will want to view their list of accounts, or an individual account. Using the default structure, a sensible URL design might be:</p>
<ul>
<li><strong>/accounts</strong> to list all accounts</li>
<li><strong>/account/details/12345678</strong> to view the transactions of a particular account</li>
</ul>
<p>The latter URL would require a Controller named &#8216;Account&#8217; containing a method named &#8216;Details&#8217;. That all sounds okay so far, but what happens when you throw Models and ORM into the mix?</p>
<p>I plan to use a hand-rolled ORM solution to handle the database interaction within the app, which would mean for the &#8216;accounts&#8217; table, my Model class would be named&#8230; &#8216;Account&#8217;. And you can&#8217;t instantiate two separate classes with the same name. Problem.</p>
<p>Assuming (and sticking with convention over configuration) that the Models have to be named correctly (&#8217;Account&#8217; for the accounts, &#8216;User&#8217; for the users, and so on), how should I decide on the naming of my Controllers?</p>
<p>As I see it, there are two options:</p>
<ol>
<li>Pick a convention for Controllers and stick to it. For example: account_controller, user_controller - I can even use <a href="http://codeigniter.com/user_guide/general/routing.html">the URL routing feature</a> to redirect my original choice for URLs to the newly named controllers, although in my experience relying on routing can start to get messy.</li>
<li>Come up with a new design for my URLs and reflect that in my Controller names. This could be anything - <strong>/show/me/12345678</strong>, <strong>/list/transactions/from/12345678</strong> - the possibilities are endless. This option has the benefit of avoiding complicated routing rules, but could prove less intutive to write and maintain.</li>
</ol>
<p>I&#8217;m leaning toward Option 2, based on a combination of disliking excessive routing and loving <a href="http://blog.welldesignedurls.org/">beautiful URL design</a>. I&#8217;d love to hear what conclusions other MVC application developers have come to, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.letsadditup.com/2008/08/08/controller-model-and-url-design/feed/</wfw:commentRss>
		</item>
		<item>
		<title>To Parse or not to Parse, that is the question</title>
		<link>http://blog.letsadditup.com/2008/07/12/to-parse-or-not-to-parse-that-is-the-question/</link>
		<comments>http://blog.letsadditup.com/2008/07/12/to-parse-or-not-to-parse-that-is-the-question/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 19:20:04 +0000</pubDate>
		<dc:creator>Matthew Pennell</dc:creator>
		
		<category><![CDATA[CodeIgniter]]></category>

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

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

		<category><![CDATA[Add new tag]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://blog.letsadditup.com/?p=17</guid>
		<description><![CDATA[When I first began to consider building a web application using CodeIgniter, one of the key aspects I had in my mind was to keep the HTML template files (the View in Model-View-Controller) as PHP-free as humanly possible.
At that time, I was planning to develop an e-commerce application (this was before the launch of Magento), [...]]]></description>
			<content:encoded><![CDATA[<p>When I first began to consider building a web application using <a href="http://codeigniter.com">CodeIgniter</a>, one of the key aspects I had in my mind was to keep the HTML template files (the View in <a href="en.wikipedia.org/wiki/Model-view-controller">Model-View-Controller</a>) as PHP-free as humanly possible.</p>
<p>At that time, I was planning to develop an e-commerce application (this was before the launch of <a href="http://www.magentocommerce.com/">Magento</a>), so my reasoning was that a distributed web app should make it easy for programmers to work on backend code while allowing designers to hack on the templates without having to understand a bunch of complicated PHP statements.</p>
<h3>CodeIgniter&#8217;s Template Parser Class</h3>
<p>To pass data from the Controller to the View in CodeIgniter, you would normally load the view template and pass in an array of data:</p>
<pre>$this-&gt;load-&gt;view('my_template', array(</pre>
<pre>    'page_name' =&gt; 'About Us',</pre>
<pre>    'page_content' =&gt; 'Hey, we are a great company!'</pre>
<pre>));</pre>
<p>The array of data is transformed into local variables for use within the template:</p>
<pre>&lt;h1&gt;&lt;?= $page_name ?&gt;&lt;/h1&gt;</pre>
<pre>&lt;p&gt;&lt;?= $page_content ?&gt;&lt;/p&gt;</pre>
<p>That&#8217;s all very well with basic variables, but when it comes to arrays your template can quickly become cluttered with nested if, else, and foreach statements - and that can be confusing for non-technical designers or purely front-end (HTML/CSS) developers.</p>
<p>The <a title="The Parser Class on the CI user guide" href="http://codeigniter.com/user_guide/libraries/parser.html">Template Parser Class</a> replaces those PHP echo statements with special variables that, in theory, are easier to understand:</p>
<pre>&lt;h1&gt;{page_title}&lt;/h1&gt;</pre>
<pre>&lt;p&gt;{page_content}&lt;/p&gt;</pre>
<pre>&lt;ul&gt;</pre>
<pre>    {link_list}</pre>
<pre>        &lt;li&gt;{link_description}&lt;/li&gt;</pre>
<pre>    {/link_list}</pre>
<pre>&lt;/ul&gt;</pre>
<p>For simple strings and basic arrays, the Parser class is easy to use - but once you start wanting to use different HTML depending on the values of your data, it can get messy. With embedded PHP in the templates, it is easy to throw a little logic into the View file - if it&#8217;s this then add that class name - but following a strict &#8220;No PHP&#8221; rule can have you jumping through hoops if your HTML isn&#8217;t architected to cope with displaying different types of data in the same way.</p>
<p>Of course, the whole point of MVC is that you <em>shouldn&#8217;t</em> be putting logic in your Views, so there really shouldn&#8217;t be any major hurdles in solely using the Parser class - but it&#8217;s going to take me a little while to get used to thinking that way.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.letsadditup.com/2008/07/12/to-parse-or-not-to-parse-that-is-the-question/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Moving the system folder in CodeIgniter</title>
		<link>http://blog.letsadditup.com/2008/07/09/moving-the-system-folder-in-codeigniter/</link>
		<comments>http://blog.letsadditup.com/2008/07/09/moving-the-system-folder-in-codeigniter/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 19:35:42 +0000</pubDate>
		<dc:creator>Matthew Pennell</dc:creator>
		
		<category><![CDATA[CodeIgniter]]></category>

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

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

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

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

		<guid isPermaLink="false">http://blog.letsadditup.com/?p=11</guid>
		<description><![CDATA[It&#8217;s the first real night of actual work on the app, and already I&#8217;ve run into my first gotcha!
For security reasons I decided to move the /system folder - which contains everything needed to run an application on CodeIgniter apart from the index.php file - outside of the web root. This is easily accomplished by [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s the first real night of actual work on the app, and already I&#8217;ve run into my first gotcha!</p>
<p>For security reasons I decided to move the <strong>/system</strong> folder - which contains everything needed to run an application on CodeIgniter apart from the <strong>index.php</strong> file - outside of the web root. This is easily accomplished by changing the <strong>$system_folder</strong> path in the aforementioned <strong>index.php</strong> file&#8230; but then everything stopped working.</p>
<p>Five minutes of head-scratching later, I figured out what I had done.</p>
<p>Because I&#8217;m working on my local development machine, instead of moving the <strong>/system</strong> folder up a level, I actually moved the <strong>index.php</strong> <em>down</em> a level - and I&#8217;d forgotten to move the <strong>.htaccess</strong> file along with it, so Apache was dutifully trying to rewrite every request to a non-existent file.</p>
<p>Stupid mistake, easy fix.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.letsadditup.com/2008/07/09/moving-the-system-folder-in-codeigniter/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
