<?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>Northern Binary &#187; CodeIgniter</title>
	<atom:link href="http://blog.northernbinary.org/category/codeigniter-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.northernbinary.org</link>
	<description></description>
	<lastBuildDate>Thu, 11 Mar 2010 10:16:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CodeIgniter and Controllers structure</title>
		<link>http://blog.northernbinary.org/php/codeigniter-and-controllers-structure/</link>
		<comments>http://blog.northernbinary.org/php/codeigniter-and-controllers-structure/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 21:58:14 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.northernbinary.org/?p=40</guid>
		<description><![CDATA[Over the weekend I was playing around with CodeIgniter. I was up and running pretty quickly and it all seemed to go pretty smoothly. Having built web applications and web sites for a number of years now and before that desktop applications etc, I&#8217;m usually pretty quick with establishing a technical structure for my site. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I was playing around with <a href="http://www.codeigniter.com" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeigniter.com');">CodeIgniter</a>. I was up and running pretty quickly and it all seemed to go pretty smoothly. Having built web applications and web sites for a number of years now and before that desktop applications etc, I&#8217;m usually pretty quick with establishing a technical structure for my site. I do this because I tend to work in iterations rather than focusing on one specific thing before moving on the next. Anyway, I became a bit frustrated when I noticed that I couldn&#8217;t subdivide my controllers folder. It seemed that I could only have one big pool of controllers. This was no good. I checked the documentation and at first I didn&#8217;t notice <a href="http://codeigniter.com/user_guide/general/controllers.html#subfolders" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/codeigniter.com');">the section that describes how to divide your controllers folder into sub folders</a>. When I finally had figured it out I ran into the next problem.</p>
<p>My site has a top level menu option called &#8216;Settings&#8217;. When you click &#8216;Settings&#8217; I want to execute the &#8217;settings&#8217; controller located in the controllers/ folder. The Settings page however has more sub-options like Users, Groups, Roles etc. and I want all these controllers to live inside a settings/ folder that&#8217;s located in the controllers/ folder:</p>
<pre>+ controllers/
   +settings/
      -users.php
      -groups.php
      -roles.php
   -settings.php</pre>
<p>This was going to clash. Going to the <em>localhost/myapp/settings</em> URL would execute the &#8217;settings&#8217; controller and going to <em>localhost/myapp/settings/users</em> would bring up a 404 error page. I assume this is because the framework tries to execute a method called &#8216;users&#8217; inside the &#8217;settings&#8217; controller.</p>
<p>Going back and forth with this issue I finally figured out a way to overcome this problem. In the routes.php configuration file you can set a default controller to execute. I&#8217;ve set mine to &#8216;index&#8217;. So, this could mean that if I would bring my settings.php file holder the Settings controller into the settings/ folder and rename it to index.php, it might execute that controller when browsing to <em>localhost/mysite/settings</em>. And behold, it does. the structure I ended up with was:</p>
<pre>+ controllers/
   +settings/
      -index.php  &lt;- default controller
      -users.php
      -groups.php
      -roles.php</pre>
<p>I haven&#8217;t tried this yet with deeper structures but I assume that the same idea applies to that as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.northernbinary.org/php/codeigniter-and-controllers-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
