<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments for Tasty Bytes</title>
	<atom:link href="http://www.tastybytes.net/comments/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tastybytes.net</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 10 Jan 2012 14:31:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Brian</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-493</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Tue, 10 Jan 2012 14:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-493</guid>
		<description>The example given above, basically is a real example in a controller.  I normally have that bit of code in the constructor of the page controller.  It&#039;s been a while since I&#039;ve used CI (or php for that matter)</description>
		<content:encoded><![CDATA[<p>The example given above, basically is a real example in a controller.  I normally have that bit of code in the constructor of the page controller.  It&#8217;s been a while since I&#8217;ve used CI (or php for that matter)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Felipe Castro</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-492</link>
		<dc:creator>Felipe Castro</dc:creator>
		<pubDate>Tue, 29 Nov 2011 02:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-492</guid>
		<description>Beautiful script for codeigniter. I&#039;ve made a few adjustments that I post bellow.

I needed to be able to configure if the user had permission to either Create, Read, Delete, or all of them.

class acl {
        /* Actions::::
         * Create   1
         * Read    2
         * Update  4
         * Delete   8
         * The allowance is made by a sum of the actions allowed.
         * Ex.: user can read and update (2+4)=6 ... so ill put 6 instead of 1 or 0.
         * 
         * if(!$this-&gt;acl-&gt;hasPermission(&#039;entries_complete_access&#039;))  {
            echo &quot;No no&quot;;
            } else 
         *  echo &quot;yeah&quot;;
            }
         * 
         * 
         */
    
    var $perms = array();  //Array : Stores the permissions for the user
    var $userID;   //Integer : Stores the ID of the current user
    var $userRoles = array(); //Array : Stores the roles of the current user
    var $ci;

    function __construct($config=array()) {
        $this-&gt;ci = &amp;get_instance();
        $this-&gt;userID = floatval($this-&gt;ci-&gt;session-&gt;userdata(&#039;account_id&#039;));
        $this-&gt;userRoles = $this-&gt;getUserRoles();
        $this-&gt;buildACL();
    }

    function buildACL() {
//first, get the rules for the user&#039;s role
        if (count($this-&gt;userRoles) &gt; 0) {
            $this-&gt;perms = array_merge($this-&gt;perms, $this-&gt;getRolePerms($this-&gt;userRoles));
        }
//then, get the individual user permissions
        $this-&gt;perms = array_merge($this-&gt;perms, $this-&gt;getUserPerms($this-&gt;userID));
        
    }

    function getPermKeyFromID($permID) {
//$strSQL = &quot;SELECT `permKey` FROM `&quot;.DB_PREFIX.&quot;permissions` WHERE `ID` = &quot; . floatval($permID) . &quot; LIMIT 1&quot;;
        $this-&gt;ci-&gt;db-&gt;select(&#039;permKey&#039;);
        $this-&gt;ci-&gt;db-&gt;where(&#039;id&#039;, floatval($permID));
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;perm_data&#039;, 1);
        $data = $sql-&gt;result();
        return $data[0]-&gt;permKey;
    }

    function getPermNameFromID($permID) {
//$strSQL = &quot;SELECT `permName` FROM `&quot;.DB_PREFIX.&quot;permissions` WHERE `ID` = &quot; . floatval($permID) . &quot; LIMIT 1&quot;;
        $this-&gt;ci-&gt;db-&gt;select(&#039;permName&#039;);
        $this-&gt;ci-&gt;db-&gt;where(&#039;id&#039;, floatval($permID));
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;perm_data&#039;, 1);
        $data = $sql-&gt;result();
        return $data[0]-&gt;permName;
    }

    function getRoleNameFromID($roleID) {
//$strSQL = &quot;SELECT `roleName` FROM `&quot;.DB_PREFIX.&quot;roles` WHERE `ID` = &quot; . floatval($roleID) . &quot; LIMIT 1&quot;;
        $this-&gt;ci-&gt;db-&gt;select(&#039;roleName&#039;);
        $this-&gt;ci-&gt;db-&gt;where(&#039;id&#039;, floatval($roleID), 1);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;role_data&#039;);
        $data = $sql-&gt;result();
        return $data[0]-&gt;roleName;
    }

    function getUserRoles() {
//$strSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;user_roles` WHERE `userID` = &quot; . floatval($this-&gt;userID) . &quot; ORDER BY `addDate` ASC&quot;;

        $this-&gt;ci-&gt;db-&gt;where(array(&#039;userID&#039; =&gt; floatval($this-&gt;userID)));
        $this-&gt;ci-&gt;db-&gt;order_by(&#039;addDate&#039;, &#039;asc&#039;);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;user_roles&#039;);
        $data = $sql-&gt;result();

        $resp = array();
        foreach ($data as $row) {

            $resp[] = $row-&gt;roleID;
        }
        return $resp;
    }

    function getAllRoles($format=&#039;ids&#039;) {
        $format = strtolower($format);
//$strSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;roles` ORDER BY `roleName` ASC&quot;;
        $this-&gt;ci-&gt;db-&gt;order_by(&#039;roleName&#039;, &#039;asc&#039;);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;role_data&#039;);
        $data = $sql-&gt;result();

        $resp = array();
        foreach ($data as $row) {
            if ($format == &#039;full&#039;) {
                $resp[] = array(&quot;id&quot; =&gt; $row-&gt;ID, &quot;name&quot; =&gt; $row-&gt;roleName);
            } else {
                $resp[] = $row-&gt;ID;
            }
        }
        return $resp;
    }

    function getAllPerms($format=&#039;ids&#039;) {
        $format = strtolower($format);
//$strSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;permissions` ORDER BY `permKey` ASC&quot;;

        $this-&gt;ci-&gt;db-&gt;order_by(&#039;permKey&#039;, &#039;asc&#039;);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;perm_data&#039;);
        $data = $sql-&gt;result();

        $resp = array();
        foreach ($data as $row) {
            if ($format == &#039;full&#039;) {
                $resp[$row-&gt;permKey] = array(&#039;id&#039; =&gt; $row-&gt;ID, &#039;name&#039; =&gt; $row-&gt;permName, &#039;key&#039; =&gt; $row-&gt;permKey);
            } else {
                $resp[] = $row-&gt;ID;
            }
        }
        return $resp;
    }

    function getRolePerms($role) {
        if (is_array($role)) {
//$roleSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;role_perms` WHERE `roleID` IN (&quot; . implode(&quot;,&quot;,$role) . &quot;) ORDER BY `ID` ASC&quot;;
            $this-&gt;ci-&gt;db-&gt;where_in(&#039;roleID&#039;, $role);
        } else {
//$roleSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;role_perms` WHERE `roleID` = &quot; . floatval($role) . &quot; ORDER BY `ID` ASC&quot;;
            $this-&gt;ci-&gt;db-&gt;where(array(&#039;roleID&#039; =&gt; floatval($role)));
        }
        $this-&gt;ci-&gt;db-&gt;order_by(&#039;id&#039;, &#039;asc&#039;);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;role_perms&#039;); //$this-&gt;db-&gt;select($roleSQL);
        $data = $sql-&gt;result();
        $perms = array();
        foreach ($data as $row) {
            $pK = strtolower($this-&gt;getPermKeyFromID($row-&gt;permID));

            if ($pK == &#039;&#039;) {
                continue;
            }
            /*if ($row-&gt;value == &#039;1&#039;) {
                $hP = true;
            } else {
                $hP = false;
            }*/
            if ($row-&gt;value == &#039;0&#039;) {
                $hP = false;
            } else {
                $hP = $row-&gt;value ;
            }

            $perms[$pK] = array(&#039;perm&#039; =&gt; $pK, &#039;1inheritted&#039; =&gt; true, &#039;value&#039; =&gt; $hP, &#039;name&#039; =&gt; $this-&gt;getPermNameFromID($row-&gt;permID), &#039;id&#039; =&gt; $row-&gt;permID);
        }
        return $perms;
    }

    function getUserPerms($userID) {
//$strSQL = &quot;SELECT * FROM `&quot;.DB_PREFIX.&quot;user_perms` WHERE `userID` = &quot; . floatval($userID) . &quot; ORDER BY `addDate` ASC&quot;;

        $this-&gt;ci-&gt;db-&gt;where(&#039;userID&#039;, floatval($userID));
        $this-&gt;ci-&gt;db-&gt;order_by(&#039;addDate&#039;, &#039;asc&#039;);
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#039;user_perms&#039;);
        $data = $sql-&gt;result();

        $perms = array();
        foreach ($data as $row) {
            $pK = strtolower($this-&gt;getPermKeyFromID($row-&gt;permID));
            if ($pK == &#039;&#039;) {
                continue;
            }
            /*if ($row-&gt;value == &#039;1&#039;) {
                $hP = true;
            } else {
                $hP = false;
            }*/
            if ($row-&gt;value == &#039;0&#039;) {
                $hP = false;
            } else {
                $hP = $row-&gt;value ;
            }
            
            $perms[$pK] = array(&#039;perm&#039; =&gt; $pK, &#039;2inheritted&#039; =&gt; false, &#039;value&#039; =&gt; $hP, &#039;name&#039; =&gt; $this-&gt;getPermNameFromID($row-&gt;permID), &#039;id&#039; =&gt; $row-&gt;permID);
        }
        return $perms;
    }

    function hasRole($roleID) {
        foreach ($this-&gt;userRoles as $k =&gt; $v) {
            if (floatval($v) === floatval($roleID)) {
                return true;
            }
        }
        return false;
    }

    function actionPerm($value, $wanted) {
        /* Actions::::
         * Create   1
         * Read,    2
         * Update,  4
         * Delete   8
         */
        $action[&#039;create&#039;] = array(&#039;1&#039;, &#039;3&#039;, &#039;5&#039;, &#039;9&#039;, &#039;11&#039;, &#039;13&#039;, &#039;15&#039;); //1
        $action[&#039;read&#039;] = array(&#039;2&#039;, &#039;3&#039;, &#039;6&#039;, &#039;10&#039;, &#039;14&#039;, &#039;15&#039;); //2
        $action[&#039;update&#039;] = array(&#039;4&#039;, &#039;5&#039;, &#039;6&#039;, &#039;7&#039;, &#039;12&#039;, &#039;13&#039;, &#039;14&#039;, &#039;15&#039;); //4
        $action[&#039;delete&#039;] = array(&#039;8&#039;, &#039;9&#039;, &#039;10&#039;, &#039;11&#039;, &#039;12&#039;, &#039;13&#039;, &#039;14&#039;, &#039;15&#039;); //8
        $action[&#039;all&#039;] = array(&#039;15&#039;);

        if (in_array($value, $action[$wanted], true)) {
            return true;
        } else {
            return false;
        }
    }

    function hasPermission($permKey, $action = &#039;all&#039;) {

        $permKey = strtolower($permKey);
                
        if (array_key_exists($permKey, $this-&gt;perms)) {
            if ($this-&gt;actionPerm($this-&gt;perms[$permKey][&#039;value&#039;], $action)) {

                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
        /* OLD METHOD
          if ($this-&gt;perms[$permKey][&#039;value&#039;] === &#039;1&#039; &#124;&#124; $this-&gt;perms[$permKey][&#039;value&#039;] === true)
          {
          return true;
          } else {
          return false;
          }
          } else {
          return false;
          }
         */
    }

}</description>
		<content:encoded><![CDATA[<p>Beautiful script for codeigniter. I&#8217;ve made a few adjustments that I post bellow.</p>
<p>I needed to be able to configure if the user had permission to either Create, Read, Delete, or all of them.</p>
<p>class acl {<br />
        /* Actions::::<br />
         * Create   1<br />
         * Read    2<br />
         * Update  4<br />
         * Delete   8<br />
         * The allowance is made by a sum of the actions allowed.<br />
         * Ex.: user can read and update (2+4)=6 &#8230; so ill put 6 instead of 1 or 0.<br />
         *<br />
         * if(!$this-&gt;acl-&gt;hasPermission(&#8216;entries_complete_access&#8217;))  {<br />
            echo &#8220;No no&#8221;;<br />
            } else<br />
         *  echo &#8220;yeah&#8221;;<br />
            }<br />
         *<br />
         *<br />
         */</p>
<p>    var $perms = array();  //Array : Stores the permissions for the user<br />
    var $userID;   //Integer : Stores the ID of the current user<br />
    var $userRoles = array(); //Array : Stores the roles of the current user<br />
    var $ci;</p>
<p>    function __construct($config=array()) {<br />
        $this-&gt;ci = &amp;get_instance();<br />
        $this-&gt;userID = floatval($this-&gt;ci-&gt;session-&gt;userdata(&#8216;account_id&#8217;));<br />
        $this-&gt;userRoles = $this-&gt;getUserRoles();<br />
        $this-&gt;buildACL();<br />
    }</p>
<p>    function buildACL() {<br />
//first, get the rules for the user&#8217;s role<br />
        if (count($this-&gt;userRoles) &gt; 0) {<br />
            $this-&gt;perms = array_merge($this-&gt;perms, $this-&gt;getRolePerms($this-&gt;userRoles));<br />
        }<br />
//then, get the individual user permissions<br />
        $this-&gt;perms = array_merge($this-&gt;perms, $this-&gt;getUserPerms($this-&gt;userID));</p>
<p>    }</p>
<p>    function getPermKeyFromID($permID) {<br />
//$strSQL = &#8220;SELECT `permKey` FROM `&#8221;.DB_PREFIX.&#8221;permissions` WHERE `ID` = &#8221; . floatval($permID) . &#8221; LIMIT 1&#8243;;<br />
        $this-&gt;ci-&gt;db-&gt;select(&#8216;permKey&#8217;);<br />
        $this-&gt;ci-&gt;db-&gt;where(&#8216;id&#8217;, floatval($permID));<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;perm_data&#8217;, 1);<br />
        $data = $sql-&gt;result();<br />
        return $data[0]-&gt;permKey;<br />
    }</p>
<p>    function getPermNameFromID($permID) {<br />
//$strSQL = &#8220;SELECT `permName` FROM `&#8221;.DB_PREFIX.&#8221;permissions` WHERE `ID` = &#8221; . floatval($permID) . &#8221; LIMIT 1&#8243;;<br />
        $this-&gt;ci-&gt;db-&gt;select(&#8216;permName&#8217;);<br />
        $this-&gt;ci-&gt;db-&gt;where(&#8216;id&#8217;, floatval($permID));<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;perm_data&#8217;, 1);<br />
        $data = $sql-&gt;result();<br />
        return $data[0]-&gt;permName;<br />
    }</p>
<p>    function getRoleNameFromID($roleID) {<br />
//$strSQL = &#8220;SELECT `roleName` FROM `&#8221;.DB_PREFIX.&#8221;roles` WHERE `ID` = &#8221; . floatval($roleID) . &#8221; LIMIT 1&#8243;;<br />
        $this-&gt;ci-&gt;db-&gt;select(&#8216;roleName&#8217;);<br />
        $this-&gt;ci-&gt;db-&gt;where(&#8216;id&#8217;, floatval($roleID), 1);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;role_data&#8217;);<br />
        $data = $sql-&gt;result();<br />
        return $data[0]-&gt;roleName;<br />
    }</p>
<p>    function getUserRoles() {<br />
//$strSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;user_roles` WHERE `userID` = &#8221; . floatval($this-&gt;userID) . &#8221; ORDER BY `addDate` ASC&#8221;;</p>
<p>        $this-&gt;ci-&gt;db-&gt;where(array(&#8216;userID&#8217; =&gt; floatval($this-&gt;userID)));<br />
        $this-&gt;ci-&gt;db-&gt;order_by(&#8216;addDate&#8217;, &#8216;asc&#8217;);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;user_roles&#8217;);<br />
        $data = $sql-&gt;result();</p>
<p>        $resp = array();<br />
        foreach ($data as $row) {</p>
<p>            $resp[] = $row-&gt;roleID;<br />
        }<br />
        return $resp;<br />
    }</p>
<p>    function getAllRoles($format=&#8217;ids&#8217;) {<br />
        $format = strtolower($format);<br />
//$strSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;roles` ORDER BY `roleName` ASC&#8221;;<br />
        $this-&gt;ci-&gt;db-&gt;order_by(&#8216;roleName&#8217;, &#8216;asc&#8217;);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;role_data&#8217;);<br />
        $data = $sql-&gt;result();</p>
<p>        $resp = array();<br />
        foreach ($data as $row) {<br />
            if ($format == &#8216;full&#8217;) {<br />
                $resp[] = array(&#8220;id&#8221; =&gt; $row-&gt;ID, &#8220;name&#8221; =&gt; $row-&gt;roleName);<br />
            } else {<br />
                $resp[] = $row-&gt;ID;<br />
            }<br />
        }<br />
        return $resp;<br />
    }</p>
<p>    function getAllPerms($format=&#8217;ids&#8217;) {<br />
        $format = strtolower($format);<br />
//$strSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;permissions` ORDER BY `permKey` ASC&#8221;;</p>
<p>        $this-&gt;ci-&gt;db-&gt;order_by(&#8216;permKey&#8217;, &#8216;asc&#8217;);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;perm_data&#8217;);<br />
        $data = $sql-&gt;result();</p>
<p>        $resp = array();<br />
        foreach ($data as $row) {<br />
            if ($format == &#8216;full&#8217;) {<br />
                $resp[$row-&gt;permKey] = array(&#8216;id&#8217; =&gt; $row-&gt;ID, &#8216;name&#8217; =&gt; $row-&gt;permName, &#8216;key&#8217; =&gt; $row-&gt;permKey);<br />
            } else {<br />
                $resp[] = $row-&gt;ID;<br />
            }<br />
        }<br />
        return $resp;<br />
    }</p>
<p>    function getRolePerms($role) {<br />
        if (is_array($role)) {<br />
//$roleSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;role_perms` WHERE `roleID` IN (&#8221; . implode(&#8220;,&#8221;,$role) . &#8220;) ORDER BY `ID` ASC&#8221;;<br />
            $this-&gt;ci-&gt;db-&gt;where_in(&#8216;roleID&#8217;, $role);<br />
        } else {<br />
//$roleSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;role_perms` WHERE `roleID` = &#8221; . floatval($role) . &#8221; ORDER BY `ID` ASC&#8221;;<br />
            $this-&gt;ci-&gt;db-&gt;where(array(&#8216;roleID&#8217; =&gt; floatval($role)));<br />
        }<br />
        $this-&gt;ci-&gt;db-&gt;order_by(&#8216;id&#8217;, &#8216;asc&#8217;);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;role_perms&#8217;); //$this-&gt;db-&gt;select($roleSQL);<br />
        $data = $sql-&gt;result();<br />
        $perms = array();<br />
        foreach ($data as $row) {<br />
            $pK = strtolower($this-&gt;getPermKeyFromID($row-&gt;permID));</p>
<p>            if ($pK == &#8221;) {<br />
                continue;<br />
            }<br />
            /*if ($row-&gt;value == &#8217;1&#8242;) {<br />
                $hP = true;<br />
            } else {<br />
                $hP = false;<br />
            }*/<br />
            if ($row-&gt;value == &#8217;0&#8242;) {<br />
                $hP = false;<br />
            } else {<br />
                $hP = $row-&gt;value ;<br />
            }</p>
<p>            $perms[$pK] = array(&#8216;perm&#8217; =&gt; $pK, &#8217;1inheritted&#8217; =&gt; true, &#8216;value&#8217; =&gt; $hP, &#8216;name&#8217; =&gt; $this-&gt;getPermNameFromID($row-&gt;permID), &#8216;id&#8217; =&gt; $row-&gt;permID);<br />
        }<br />
        return $perms;<br />
    }</p>
<p>    function getUserPerms($userID) {<br />
//$strSQL = &#8220;SELECT * FROM `&#8221;.DB_PREFIX.&#8221;user_perms` WHERE `userID` = &#8221; . floatval($userID) . &#8221; ORDER BY `addDate` ASC&#8221;;</p>
<p>        $this-&gt;ci-&gt;db-&gt;where(&#8216;userID&#8217;, floatval($userID));<br />
        $this-&gt;ci-&gt;db-&gt;order_by(&#8216;addDate&#8217;, &#8216;asc&#8217;);<br />
        $sql = $this-&gt;ci-&gt;db-&gt;get(&#8216;user_perms&#8217;);<br />
        $data = $sql-&gt;result();</p>
<p>        $perms = array();<br />
        foreach ($data as $row) {<br />
            $pK = strtolower($this-&gt;getPermKeyFromID($row-&gt;permID));<br />
            if ($pK == &#8221;) {<br />
                continue;<br />
            }<br />
            /*if ($row-&gt;value == &#8217;1&#8242;) {<br />
                $hP = true;<br />
            } else {<br />
                $hP = false;<br />
            }*/<br />
            if ($row-&gt;value == &#8217;0&#8242;) {<br />
                $hP = false;<br />
            } else {<br />
                $hP = $row-&gt;value ;<br />
            }</p>
<p>            $perms[$pK] = array(&#8216;perm&#8217; =&gt; $pK, &#8217;2inheritted&#8217; =&gt; false, &#8216;value&#8217; =&gt; $hP, &#8216;name&#8217; =&gt; $this-&gt;getPermNameFromID($row-&gt;permID), &#8216;id&#8217; =&gt; $row-&gt;permID);<br />
        }<br />
        return $perms;<br />
    }</p>
<p>    function hasRole($roleID) {<br />
        foreach ($this-&gt;userRoles as $k =&gt; $v) {<br />
            if (floatval($v) === floatval($roleID)) {<br />
                return true;<br />
            }<br />
        }<br />
        return false;<br />
    }</p>
<p>    function actionPerm($value, $wanted) {<br />
        /* Actions::::<br />
         * Create   1<br />
         * Read,    2<br />
         * Update,  4<br />
         * Delete   8<br />
         */<br />
        $action['create'] = array(&#8217;1&#8242;, &#8217;3&#8242;, &#8217;5&#8242;, &#8217;9&#8242;, &#8217;11&#8242;, &#8217;13&#8242;, &#8217;15&#8242;); //1<br />
        $action['read'] = array(&#8217;2&#8242;, &#8217;3&#8242;, &#8217;6&#8242;, &#8217;10&#8242;, &#8217;14&#8242;, &#8217;15&#8242;); //2<br />
        $action['update'] = array(&#8217;4&#8242;, &#8217;5&#8242;, &#8217;6&#8242;, &#8217;7&#8242;, &#8217;12&#8242;, &#8217;13&#8242;, &#8217;14&#8242;, &#8217;15&#8242;); //4<br />
        $action['delete'] = array(&#8217;8&#8242;, &#8217;9&#8242;, &#8217;10&#8242;, &#8217;11&#8242;, &#8217;12&#8242;, &#8217;13&#8242;, &#8217;14&#8242;, &#8217;15&#8242;); //8<br />
        $action['all'] = array(&#8217;15&#8242;);</p>
<p>        if (in_array($value, $action[$wanted], true)) {<br />
            return true;<br />
        } else {<br />
            return false;<br />
        }<br />
    }</p>
<p>    function hasPermission($permKey, $action = &#8216;all&#8217;) {</p>
<p>        $permKey = strtolower($permKey);</p>
<p>        if (array_key_exists($permKey, $this-&gt;perms)) {<br />
            if ($this-&gt;actionPerm($this-&gt;perms[$permKey]['value'], $action)) {</p>
<p>                return true;<br />
            } else {<br />
                return false;<br />
            }<br />
        } else {<br />
            return false;<br />
        }<br />
        /* OLD METHOD<br />
          if ($this-&gt;perms[$permKey]['value'] === &#8217;1&#8242; || $this-&gt;perms[$permKey]['value'] === true)<br />
          {<br />
          return true;<br />
          } else {<br />
          return false;<br />
          }<br />
          } else {<br />
          return false;<br />
          }<br />
         */<br />
    }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by pico</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-491</link>
		<dc:creator>pico</dc:creator>
		<pubDate>Wed, 02 Nov 2011 08:03:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-491</guid>
		<description>Hey, thanks for you tutorial. But i hope to see with a controller to use this libraries. If it possible let&#039;s me know coz of i&#039;m newbie in CI. I have no idea how to use it. But still hope this tutorial will help me alot</description>
		<content:encoded><![CDATA[<p>Hey, thanks for you tutorial. But i hope to see with a controller to use this libraries. If it possible let&#8217;s me know coz of i&#8217;m newbie in CI. I have no idea how to use it. But still hope this tutorial will help me alot</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Pedma</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-158</link>
		<dc:creator>Pedma</dc:creator>
		<pubDate>Mon, 18 Jul 2011 12:33:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-158</guid>
		<description>Hi,

I&#039;m new in CodeIgniter. 
Could you please give a real example how to use this ACL ? 
Is it possible to use this for &#039;simple login&#039;  ( http://codeigniter.com/wiki/Simplelogin/ ) ? 

Thanks
-pedma-</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m new in CodeIgniter.<br />
Could you please give a real example how to use this ACL ?<br />
Is it possible to use this for &#8216;simple login&#8217;  ( <a href="http://codeigniter.com/wiki/Simplelogin/" rel="nofollow">http://codeigniter.com/wiki/Simplelogin/</a> ) ? </p>
<p>Thanks<br />
-pedma-</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Brian</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-37</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 06 Jun 2011 14:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-37</guid>
		<description>For me, it was a need for:
- User by user permissions
- Multiple Roles
- Database configured

While the Zend ACL may offer these, I didn&#039;t have the time to look through countless tutorials etc looking for something I already &quot;had&quot;.

It also came down to an easy of use issue.  This class is pretty much very straight forward when it comes to setting it up and using it.</description>
		<content:encoded><![CDATA[<p>For me, it was a need for:<br />
- User by user permissions<br />
- Multiple Roles<br />
- Database configured</p>
<p>While the Zend ACL may offer these, I didn&#8217;t have the time to look through countless tutorials etc looking for something I already &#8220;had&#8221;.</p>
<p>It also came down to an easy of use issue.  This class is pretty much very straight forward when it comes to setting it up and using it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by JonoB</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-36</link>
		<dc:creator>JonoB</dc:creator>
		<pubDate>Mon, 06 Jun 2011 13:22:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-36</guid>
		<description>Brian,

This is great, thank you. I am looking to implement ACL in a CI project, and was looking at Zend_Acl, until I stumbled across your website. As a matter of interest, what does the Zend implementation miss out on that yours does provide?</description>
		<content:encoded><![CDATA[<p>Brian,</p>
<p>This is great, thank you. I am looking to implement ACL in a CI project, and was looking at Zend_Acl, until I stumbled across your website. As a matter of interest, what does the Zend implementation miss out on that yours does provide?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Brian</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-12</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 02 May 2011 21:44:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-12</guid>
		<description>Is your existing login system based on the Code Igniter framework?

If not, this script will be pretty difficult to translate it over.  

read this link, it is a really well written walk through of the script.

http://net.tutsplus.com/tutorials/php/a-better-login-system/</description>
		<content:encoded><![CDATA[<p>Is your existing login system based on the Code Igniter framework?</p>
<p>If not, this script will be pretty difficult to translate it over.  </p>
<p>read this link, it is a really well written walk through of the script.</p>
<p><a href="http://net.tutsplus.com/tutorials/php/a-better-login-system/" rel="nofollow">http://net.tutsplus.com/tutorials/php/a-better-login-system/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by ken</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-9</link>
		<dc:creator>ken</dc:creator>
		<pubDate>Wed, 20 Apr 2011 13:20:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-9</guid>
		<description>how can i intergrate this on a existing login system... fairly new to PHP...</description>
		<content:encoded><![CDATA[<p>how can i intergrate this on a existing login system&#8230; fairly new to PHP&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Simple ACL Class for CodeIgniter by Nishan Karassik</title>
		<link>http://www.tastybytes.net/blog/simple-acl-class-for-codeigniter#comment-3</link>
		<dc:creator>Nishan Karassik</dc:creator>
		<pubDate>Thu, 31 Mar 2011 06:52:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.tastybytes.net/2010/08/1-revision-14/#comment-3</guid>
		<description>Thanks for putting this together.  I looked an looked and didn&#039;t like Zend Acl either.

I have made a few adustments and will make a few more as I dig a little deeper on a new project, but I thought I would throw these out there.

The hasRole function bothered me because it needed the roleid instead of roleName.  I had to change getUserRoles and the hasRole functions as follows:

function getUserRoles() {
				//$strSQL = &quot;SELECT UR.roleid, LOWER(RD.roleName) roleName FROM `&quot;.DB_PREFIX.&quot;user_roles` UR 
				//INNER JOIN role_data RD ON RD.id = UR.roleid WHERE `userid` = &quot; . floatval($this-&gt;userid) . &quot; 
				//ORDER BY `addDate` ASC&quot;;
				$this-&gt;ci-&gt;db-&gt;select(&#039;UR.roleid, LOWER(RD.roleName) roleName&#039;);
				$this-&gt;ci-&gt;db-&gt;from(&#039;user_roles UR&#039;);
				$this-&gt;ci-&gt;db-&gt;join(&#039;role_data RD&#039;, &#039;RD.id = UR.roleid&#039;);
				$this-&gt;ci-&gt;db-&gt;where(array(&#039;userid&#039;=&gt;floatval($this-&gt;userid)));
				$this-&gt;ci-&gt;db-&gt;order_by(&#039;addDate&#039;,&#039;asc&#039;);
				$sql = $this-&gt;ci-&gt;db-&gt;get();
				$data = $sql-&gt;result();
 
				$resp = array();
				foreach( $data as $row )
				{
						$resp[$row-&gt;roleName] = $row-&gt;roleid;
				}
				return $resp;
		}

AND

		function hasRole($roleName) { 
				$roleName = strtolower($roleName);
				foreach($this-&gt;userRoles as $k =&gt; $v)
				{
						if ($k === $roleName)
						{
								return true;
						}
				}
				return false;
		}

I will likely do similar adjustments to the getRolePerms($role) to instead use roleName when I start developing the admin panel for this.

Also I&#039;ve changed the &#039;value&#039; field in both tables and appropriate functions to &#039;active&#039;.  If I&#039;m understanding the design it&#039;s more descriptive.</description>
		<content:encoded><![CDATA[<p>Thanks for putting this together.  I looked an looked and didn&#8217;t like Zend Acl either.</p>
<p>I have made a few adustments and will make a few more as I dig a little deeper on a new project, but I thought I would throw these out there.</p>
<p>The hasRole function bothered me because it needed the roleid instead of roleName.  I had to change getUserRoles and the hasRole functions as follows:</p>
<p>function getUserRoles() {<br />
				//$strSQL = &#8220;SELECT UR.roleid, LOWER(RD.roleName) roleName FROM `&#8221;.DB_PREFIX.&#8221;user_roles` UR<br />
				//INNER JOIN role_data RD ON RD.id = UR.roleid WHERE `userid` = &#8221; . floatval($this-&gt;userid) . &#8221;<br />
				//ORDER BY `addDate` ASC&#8221;;<br />
				$this-&gt;ci-&gt;db-&gt;select(&#8216;UR.roleid, LOWER(RD.roleName) roleName&#8217;);<br />
				$this-&gt;ci-&gt;db-&gt;from(&#8216;user_roles UR&#8217;);<br />
				$this-&gt;ci-&gt;db-&gt;join(&#8216;role_data RD&#8217;, &#8216;RD.id = UR.roleid&#8217;);<br />
				$this-&gt;ci-&gt;db-&gt;where(array(&#8216;userid&#8217;=&gt;floatval($this-&gt;userid)));<br />
				$this-&gt;ci-&gt;db-&gt;order_by(&#8216;addDate&#8217;,'asc&#8217;);<br />
				$sql = $this-&gt;ci-&gt;db-&gt;get();<br />
				$data = $sql-&gt;result();</p>
<p>				$resp = array();<br />
				foreach( $data as $row )<br />
				{<br />
						$resp[$row-&gt;roleName] = $row-&gt;roleid;<br />
				}<br />
				return $resp;<br />
		}</p>
<p>AND</p>
<p>		function hasRole($roleName) {<br />
				$roleName = strtolower($roleName);<br />
				foreach($this-&gt;userRoles as $k =&gt; $v)<br />
				{<br />
						if ($k === $roleName)<br />
						{<br />
								return true;<br />
						}<br />
				}<br />
				return false;<br />
		}</p>
<p>I will likely do similar adjustments to the getRolePerms($role) to instead use roleName when I start developing the admin panel for this.</p>
<p>Also I&#8217;ve changed the &#8216;value&#8217; field in both tables and appropriate functions to &#8216;active&#8217;.  If I&#8217;m understanding the design it&#8217;s more descriptive.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

