<?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>Matt Stone, that's me</title>
	<atom:link href="http://www.mattstone.me/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.mattstone.me</link>
	<description>Another geek clogging up the tubes</description>
	<lastBuildDate>Sun, 09 Aug 2009 05:25:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Techno Trance Mix Uploaded</title>
		<link>http://www.mattstone.me/?p=53</link>
		<comments>http://www.mattstone.me/?p=53#comments</comments>
		<pubDate>Sun, 09 Aug 2009 05:25:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattstone.me/?p=53</guid>
		<description><![CDATA[After a request for some music from a good friend of mine I&#8217;ve started work on getting some of my old dj mixes uploaded for your listening pleasure. The first one is a mix I recorded several years ago now and went down well with everyone who nabbed a free cd from me.  Usually I [...]]]></description>
			<content:encoded><![CDATA[<p>After a request for some music from a good friend of mine I&#8217;ve started work on getting some of my old dj mixes uploaded for your listening pleasure.</p>
<p>The first one is a mix I recorded several years ago now and went down well with everyone who nabbed a free cd from me.  Usually I get tired of my own mixes pretty quickly but after a couple of years of not listening to this one it&#8217;s grown on me again <img src='http://www.mattstone.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   So, without further ado, here&#8217;s the link <a href="http://www.mattstone.me/audio/03062005.mp3">http://www.mattstone.me/audio/03062005.mp3</a> and for anyone who&#8217;s interested the tracklisting is as follows&#8230;</p>
<table border="0">
<tbody>
<tr>
<th style="width: 33%; text-align: left">Artist</th>
<th style="width: 33%; text-align: left">Title</th>
<th style="width: 33%; text-align: left">Label</th>
</tr>
<tr>
<td>Mellow Trax Feat. Shaft</td>
<td>Sway</td>
<td>EDM</td>
</tr>
<tr>
<td>Miss Loony</td>
<td>Explain(DJ Tatana Mix)</td>
<td>Sirup</td>
</tr>
<tr>
<td>Nick Sentience</td>
<td>Freedom</td>
<td>Nukleuz</td>
</tr>
<tr>
<td>Chrome</td>
<td>Ritmo Del Mundo</td>
<td>Taach!</td>
</tr>
<tr>
<td>Cloudburst</td>
<td>The Mission(Club Mix)</td>
<td>Drizzly</td>
</tr>
<tr>
<td>Groovelikers</td>
<td>Groovelike(Snuggle Duggle Mix)</td>
<td>Drop Out</td>
</tr>
<tr>
<td>Tony Walker</td>
<td>Fields of Joy(Flutlicht Mix)</td>
<td>Drizzly</td>
</tr>
<tr>
<td>Muzz &amp; Diggs</td>
<td>World of Tomorrow(MD Re-edit)</td>
<td>Subliminal Heights</td>
</tr>
<tr>
<td>Adelphoi</td>
<td>A Better Tomorrrow</td>
<td>Ascendant Heights</td>
</tr>
<tr>
<td>Helikopter</td>
<td>Der Rotor(Manover Mix)</td>
<td>Edel</td>
</tr>
<tr>
<td>DJ Session One meets Manuel Oetl</td>
<td>Trip to Africa(Club Mix)</td>
<td>Blutonium</td>
</tr>
<tr>
<td>D-Devils</td>
<td>Sex &amp; Drugs &amp; House(Stormtraxx Mix)</td>
<td>Byte</td>
</tr>
<tr>
<td>Sergeant Sam</td>
<td>???????</td>
<td>Storm Trance</td>
</tr>
<tr>
<td>Kaylab pt2</td>
<td>Here We Go(Jam X &amp; De Leon Mix)</td>
<td>????</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.mattstone.me/?feed=rss2&amp;p=53</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.mattstone.me/audio/03062005.mp3" length="68820869" type="audio/mpeg" />
		</item>
		<item>
		<title>Using the Zend Framework ACL Library in Codeigniter</title>
		<link>http://www.mattstone.me/?p=3</link>
		<comments>http://www.mattstone.me/?p=3#comments</comments>
		<pubDate>Sun, 23 Nov 2008 21:04:28 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[code igniter]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.mattstone.me/?p=3</guid>
		<description><![CDATA[To kick my blog off good and proper I thought a tutorial on implementing the Zend Framework ACL library into a Code Igniter application would be a nice start. In this post I will explain how to build simple access control functionality for your Code Igniter application using the Zend Framework ACL library. To follow [...]]]></description>
			<content:encoded><![CDATA[<p>To kick my blog off good and proper I thought a tutorial on implementing the Zend Framework ACL library into a Code Igniter application would be a nice start.</p>
<p>In this post I will explain how to build simple access control functionality for your Code Igniter application using the Zend Framework ACL library. To follow this tutorial you will need a working installation of Code Igniter and a database. You will also need to download the Zend Framework.</p>
<h2>Code Igniter and Access Control Lists</h2>
<p>A lot of Code Igniter users have complained that the framework doesn&#8217;t come bundled with an access control component unlike other heavyweight frameworks such as Symfony and CakePHP. Personally I don&#8217;t see this as a major issue as the developers behind Code Igniter have deliberately kept it lean with unnecessary libraries being left out in favour of a solid and very usable core and not every web app needs access control.</p>
<p>In my current job access control was an essential requirement and, being the sole person responsible for choosing code igniter over other frameworks, it&#8217;s down to me to implement some form of access control into our app.</p>
<p>I started by looking at rolling my own but decided that instead of reinventing the wheel it would be far better to go with a tried and trusted solution hence my reason for opting for the Zend Framework ACL implementation.</p>
<h2>Zend ACL</h2>
<p>The <a href="http://framework.zend.com/manual/en/zend.acl.html">Zend ACL</a> implementation provides a flexible approach to Access Control Lists with a simple querying interface supplying either true or false. It&#8217;s up to the developer to decide how to implement their permissions but I&#8217;ll give an example based on the application (a CMS) I&#8217;m currently developing.</p>
<h2>Getting Started</h2>
<p>To start with I&#8217;ll link to the blog post that got me started&#8230; A very good primer for getting your ACL up and running using the Zend Framework and a database can be found at <a href="http://my.opera.com/zomg/blog/2007/05/08/zend-acl-and-storing-roles-and-resources-in-a-db">Jani&#8217;s blog</a> it helped me no end and formed the basis for this write up. Now on to the nitty gritty&#8230;</p>
<p><a href="http://framework.zend.com/download/latest">Download the Zend framework</a> and unzip it to your code igniter install in /system/libraries. You can leave the whole framework there if you want but if it&#8217;s just the ACL stuff you need you can remove everything except Acl.php, Exception.php and the Acl folder.</p>
<p>After that create a file called Acl.php in /system/application/libraries, open it up in your favourite editor and pop this code in it&#8230;</p>

<div class="wp_codebox"><table width="100%" ><tr id="p36"><td class="code" id="p3code6"><pre class="php" style="font-family:monospace;"><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> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><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: #b1b100;">require_once</span> BASEPATH <span style="color: #339933;">.</span><span style="color: #0000ff;">'libraries/Zend/Acl.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Acl <span style="color: #000000; font-weight: bold;">extends</span> Zend_Acl <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>
		<span style="color: #000088;">$CI</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>get_instance<span style="color: #009900;">&#40;</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;">acl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Acl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ParentId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Get the roles</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_roles'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$roles</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parentId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Get the resources</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_resources'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_permissions'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Get the permissions</span>
		<span style="color: #000088;">$permissions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$roles</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$roles</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Add the roles to the ACL</span>
			<span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Acl_Role<span style="color: #009900;">&#40;</span><span style="color: #000088;">$roles</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$roles</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</span> <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">null</span> ?
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRole</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span><span style="color: #000088;">$roles</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRole</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$resources</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Add the resources to the ACL</span>
			<span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Acl_Resource<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</span> <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">null</span> ?
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$permissions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Add the permissions to the ACL</span>
			<span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span> ? 
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'read'</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'read'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span> ? 
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'write'</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modify</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span> ? 
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'modify'</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'modify'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span> ? 
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'publish'</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'publish'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span> ? 
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'delete'</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;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Change this to whatever id your adminstrators group is</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">/*
	 * Methods to query the ACL.
	 */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> can_read<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'read'</span><span style="color: #009900;">&#41;</span>? <span style="color: #000000; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> can_write<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'write'</span><span style="color: #009900;">&#41;</span>? <span style="color: #000000; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> can_modify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'modify'</span><span style="color: #009900;">&#41;</span>? <span style="color: #000000; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> can_delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'delete'</span><span style="color: #009900;">&#41;</span>? <span style="color: #000000; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">function</span> can_publish<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'publish'</span><span style="color: #009900;">&#41;</span>? <span style="color: #000000; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>IMPORTANT!</strong> The final line in the constructor allows all permissions for the role with an ID of 3. This is purely for demonstration purposes. I&#8217;m assuming you&#8217;ll create an admin role in your database before deploying your app so make sure this ID corresponds with your admin role.</p>
<h2>The Database Tables</h2>
<p>Next we need to create the database tables we&#8217;ll be using for the Acl. For that we only need 3 tables, user_permissions, user_resources and user_roles. The sql for those tables is as follows&#8230;</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37"><td class="code" id="p3code7"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`user_resources`</span> <span style="color: #66cc66;">&#40;</span>
       <span style="color: #ff0000;">`id`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`parentId`</span> INT <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
     <span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`user_roles`</span> <span style="color: #66cc66;">&#40;</span>
       <span style="color: #ff0000;">`id`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`parentId`</span> INT <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
     <span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`user_permissions`</span> <span style="color: #66cc66;">&#40;</span>
       <span style="color: #ff0000;">`id`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`role`</span> INT
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`resource`</span> INT
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`read`</span> <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> FALSE
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`write`</span> <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> FALSE
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`modify`</span> <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> FALSE
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`delete`</span> <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> FALSE
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`publish`</span> <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> FALSE
     <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>The user_resources table holds the data for the resources we want to protect through the ACL. Typically this will be admin controllers for any area of your site and perhaps restricted areas of your site such as user profiles or forums. Both the description and parentId fields are optional, the description is there purely for an admin backend to the ACL, the parentId allows you to inherit permissions from a resource, for example you could have separate CMS and media library controllers and you would like the media library to inherit permissions from the CMS so for the media library you would insert the id of the CMS resource into the parent field for the media library.</p>
<p>The user_roles table works in the same way as the resources table. Roles can inherit from other roles allowing you to build permissions with a minimal number of groups. For example you could have a CMS users role which has all permissions except for publish and delete, you could then create a CMS editors role which inherits from the CMS users role but adds extra permissions for deleting and publishing content.</p>
<p>The final table, user_permisssions, is what builds the permissions in the acl. If needs be you can add as many boolean columns for whatever permissions your application requires, just remember to add a method in your ACL library for querying that permission! The description field is, like the other tables, optional but for the purposes of an admin backend you&#8217;ll probably want to use it!</p>
<p>We can now start by populating our tables&#8230;</p>

<div class="wp_codebox"><table width="100%" ><tr id="p38"><td class="code" id="p3code8"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`user_resources`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`parentId`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Acl Test Controller'</span><span style="color: #66cc66;">,</span> NULLL<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`user_roles`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`parentId`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Acl Test Role'</span><span style="color: #66cc66;">,</span> NULLL<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`user_permissions`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`role`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`resource`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`read`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`write`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`modify`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`delete`</span> <span style="color: #66cc66;">,</span><span style="color: #ff0000;">`publish`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<h2>Testing the ACL</h2>
<p>We&#8217;re now ready to test out the ACL. Create a controller test.php in /system/application/controllers with the following code.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p39"><td class="code" id="p3code9"><pre class="php" style="font-family:monospace;"><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> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><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: #000000; font-weight: bold;">class</span> Test <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">function</span>  Test<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: #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;">'Acl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ROLE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RESOURCE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">can_read</span><span style="color: #009900;">&#40;</span>ROLE<span style="color: #339933;">,</span> RESOURCE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You do not have permissions to read this resource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;You have permission to read this resource!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">function</span> write<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">can_write</span><span style="color: #009900;">&#40;</span>ROLE<span style="color: #339933;">,</span> RESOURCE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You do not have permissions to write to this resource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;You have permission to write to this resource!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">function</span> modify<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">can_modify</span><span style="color: #009900;">&#40;</span>ROLE<span style="color: #339933;">,</span> RESOURCE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You do not have permissions to modify this resource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;You have permission to modify this resource!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">function</span> delete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">can_delete</span><span style="color: #009900;">&#40;</span>ROLE<span style="color: #339933;">,</span> RESOURCE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You do not have permissions to delete this resource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;You have permission to delete this resource!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">function</span> publish<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">can_publish</span><span style="color: #009900;">&#40;</span>ROLE<span style="color: #339933;">,</span> RESOURCE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You do not have permissions to publish this resource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;You have permission to publish this resource!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>For the purposes of this article I&#8217;m going to assume your working on your local machine, so browse to <a href="http://localhost/test">http://localhost/test</a>. You should see the message &#8220;You have permission to read this resource&#8221;. Next try <a href="http://localhost/test/delete">http://localhost/test/delete</a>. You should see the message &#8220;You do not have permission to delete this resource&#8221;. Now go and try it on all the methods in your test controller.</p>
<p>Congratulations! You&#8217;ve successfully got Code Igniter and Zend ACL to play nicely together.</p>
<p><strong>Note:</strong> If you get error messages about required files not being found in the include path you may have to modify the include paths in your Zend framework files. Open them up and, wherever you find an include or require, modify it to&#8230;</p>

<div class="wp_codebox"><table width="100%" ><tr id="p310"><td class="code" id="p3code10"><pre class="php" style="font-family:monospace;">BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/libraries/REST OF THE FILE PATH'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Summary</h2>
<p>While the above article explains how to get access control working in code igniter it doesn&#8217;t provide a model for obtaining roles and resources, the above example having the role and resource id hardcoded into the controller. This is an exercise I feel that is best left to the developer. Personally I use the excellent <a href="http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/">modular extensions</a> for organising my application. I then have a separate module model which has a method get_resource_id which allows me to define the resource.</p>
<p>The users id is held in their session and I have a users model which, again, has to method to define their role from their session.</p>
<p>It&#8217;s also worth noting that if you try and check the ACL without either the role or resource being valid you&#8217;ll get an exception error so whichever way you decide to implement this it&#8217;s best to write some basic checks before querying the ACL.</p>
<h2>The End</h2>
<p>Ok, I hope some people have found this useful, let the comments commence!</p>
<p>Thank you for listening.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattstone.me/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>
