<?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>Promet CakePHP Source &#187; CakePHP 1.2</title>
	<atom:link href="http://cakephp.prometsupport.com/category/cakephp-12/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakephp.prometsupport.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 Feb 2009 08:03:07 +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>INI Based Permission Component</title>
		<link>http://cakephp.prometsupport.com/2009/ini-based-permission-component/</link>
		<comments>http://cakephp.prometsupport.com/2009/ini-based-permission-component/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 13:37:42 +0000</pubDate>
		<dc:creator>rachel</dc:creator>
				<category><![CDATA[Behaviors]]></category>
		<category><![CDATA[CakePHP 1.1]]></category>
		<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Tips & Tutorials]]></category>
		<category><![CDATA[cakePHP websites]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/?p=142</guid>
		<description><![CDATA[Yet another permission component was created this week but this time, it&#8217;s simplier and written in a text file. In one of our project, one of the follow-up requirement was to allow users of certain groups upgrade into a better status. The project was already in production and I was using ACL with Auth component [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another permission component was created this week but this time, it&#8217;s simplier and written in a text file. In one of our project, one of the follow-up requirement was to allow users of certain groups upgrade into a better status. The project was already in production and I was using ACL with Auth component to do my authentication. Unfortunately, this is one of <a href="http://www.mail-archive.com/cake-php@googlegroups.com/msg57645.html">ACLs weakness</a>. </p>
<blockquote><p>Changing a users group does not change the ARO parent (effectively making it useless/impossible to change groups). I tried fixing this home-brew style, but since there&#8217;s no setParent in 1.2&#8242;s db_acl, it&#8217;s far harder than it should be.</p>
</blockquote>
<p>That was reported back in 2007 and there was still no solution found in the net. It is also not an option for me to go through the above suggestion in fixing the problem so the the other solution is to find another one or create one. I chose the latter.</p>
<p><strong>Why create a new one?</strong></p>
<p>The other solutions that I found still needs some configuration in the controllers. Since I already have a ton of files, I don&#8217;t want to go through all of them to add a line or two. I need ACLs way of doing it all in the background. Also, I am already using Auth component and I want to keep it.</p>
<p><strong>Why did I choose a text file over a database?</strong></p>
<p>My intention is to make the application faster since load time is really getting slower. Since the application isn&#8217;t that big, I only have less than 200 lines for the permissions, so a database is just overkill. Even if I use a database, I might cache it anyway so it saves me extra query.</p>
<p><strong>The component</strong></p>
<p>So Permission Component was created. Below is the instruction on how to install it.</p>
<ol>
<li><a href='http://cakephp.prometsupport.com/wp-content/uploads/2009/01/permissionphp.txt'>Download this component</a> and copy to your components folder. </li>
<li>Create cake_dir/app/config/permissions.ini</li>
</ol>
<p>The content for permissions.ini is as follows</p>
<p><code lang="ini[lines]"><br />
[ControllerName]<br />
actionName = group_id,group_id<br />
 <br />
[PluginName.ControllerName]<br />
actionName = group_id,group_id<br />
</code></p>
<p>The <em>ControllerName</em> should be the controller name itself (in camel-case format).</p>
<p>The <em>actionName</em> is also the action name itself (in camel-case format).</p>
<p>The <em>PluginName</em> is the plugin name itself (in camel-case format).</p>
<p>The <em>group_id</em> is the one written in your Auth component. Your Auth component should have a group_id value because this is what our Permission component will look for. It could be a number or set of characters.</p>
<p>Example:</p>
<p><code lang="ini[lines]"><br />
; Group ID 1 = Admin<br />
; Group ID 2 = Member<br />
[Accounts]<br />
index =<br />
add = 1<br />
edit = 1,2<br />
delete = 1,2<br />
 <br />
[ShoppingCart.Orders]<br />
index =<br />
report = 1<br />
</code></p>
<p>Assigning no group id in an actionName will simply ignore it.</p>
<p><strong>Reminder</strong></p>
<p>Use at your own risk. If you found a bug, please post them at the comment form.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2009/ini-based-permission-component/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Bake a New Project in CakePhp</title>
		<link>http://cakephp.prometsupport.com/2008/learn-how-to-bake-cakephp-app/</link>
		<comments>http://cakephp.prometsupport.com/2008/learn-how-to-bake-cakephp-app/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 13:35:50 +0000</pubDate>
		<dc:creator>rachel</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Tips & Tutorials]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[bake]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/?p=103</guid>
		<description><![CDATA[div.block {margin: .5em 25px; background-color: #efefef; padding: .5em;} div.note {margin: .5em 25px; background-color: #fffbcc; padding: .5em;} I use bake to start any project of mine and therefore doesn&#8217;t mean that using it produces a complete app unless you only want a CRUD application. This tutorial is intended for beginners in cakephp. It is still recommended [...]]]></description>
			<content:encoded><![CDATA[<style>
div.block {margin: .5em 25px; background-color: #efefef; padding: .5em;}
div.note {margin: .5em 25px; background-color: #fffbcc; padding: .5em;}
</style>
<p>I use bake to start any project of mine and therefore doesn&#8217;t mean that using it produces a complete app unless you only want a CRUD application.</p>
<p>This tutorial is intended for beginners in cakephp. It is still recommended that you look at the <a href="http://book.cakephp.org/view/219/Blog">blog tutorial</a> in cakephp manual because it has a more complete introduction for the framework. </p>
<p>Take note that I am using the <a rel="nofollow" href="http://cakeforge.org/frs/?group_id=23&#038;release_id=426">Cakephp 1.2.0.7692 RC3</a> in demonstrating this little project because it is the latest release as of this writing. </p>
<h2>What to do and what do we need to begin?</h2>
<p>To start off, we need a project. I opted a mini-library application which consists of</p>
<div class="block">Books<br />
Authors<br />
Book reviews by users
</div>
<p><span id="more-103"></span><br />
The mini-library will store different books. Each books can have one or more authors and one or more reviews created by users. So we will have the following tables</p>
<div class="block">authors<br />
books<br />
books_authors<br />
book_reviews<br />
users
</div>
<p>And they have the following relationships:</p>
<div class="block">books can have many authors<br />
authors can have many books<br />
books can have many reviews<br />
users can have many reviews<br />
a review is owned by a book
</div>
<p><a href='http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cakedemo_1.sql'>Download the SQL</a> and create your database.</p>
<h2>Let&#8217;s start baking!</h2>
<p>Since our topic is about baking, we will maximize the use of cake CLI. First, setup your environment so that it will accept the cake command. For Ubuntu users, it is already available in synaptic or use apt-get</p>
<p><code lang="bash">sudo apt-get install cakephp1.2-scripts</code></p>
<p>For windows users, I used this <a rel="nofollow" href="http://www.webdevelopment2.com/cakephp-bake-baking-models-controllers-views-cakephp-12/">tutorial for setting up Windows</a>.</p>
<div class="note">The following steps is done in Windows so I cannot guarantee the result will be the same in Ubuntu.</div>
<p>Once you have setup your environment, everything is just easy. I do not think I even need to tell you what you need to do but I still will since I already started it:P</p>
<p>You just need to remember this steps:</p>
<ol>
<li>Create a project. This creates all the files and directories under the /app directory</li>
<li>Configure database.php. We will do that using the command line</li>
<li>Start creating your Models. As the blog tutorial mentioned, models are the bread and butter of cakephp.</li>
<li>Create your controllers </li>
<li>Finally, create your views</li>
<li>Check your new app!</li>
</ol>
<p>So let&#8217;s start doing something and stop talking eh? </p>
<p>Open your command line and go to your www directory or wherever you want to create your cakephp project. Do not yet create folder for this project. So in my case, my web directory is E:\www\. Type </p>
<p><code lang="bash">cake bake </code></p>
<p>It will ask you to create your project since it cannot find an existing one. </p>
<p><b>Step 1: Create project</b><br />
I created <em>mylibrary</em> project. Here is the output.</p>
<p><a href="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake1.png"><img src="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake1-300x181.png" alt="CakePhp bake step 1 - Create Project" title="cake_bake1" width="300" height="181" class="size-medium wp-image-121" /></a></p>
<p><b>Step 2: Configure database</b><br />
Then it will ask you to create your database config. In my example, my database name is <em>cakedemo_1</em>.</p>
<p><a href="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake2.png"><img src="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake2-300x247.png" alt="CakePhp bake step 2 - Configure database" title="cake_bake2" width="300" height="247" class="size-medium wp-image-122" /></a></p>
<p>And we&#8217;re done with the installation. If you will check your files, <em>mylibrary</em> folder is created in E:\www. <em>mylibrary</em> already contains all the necessary files and folders to start building your app. To check, go to <u>http://localhost/mylibrary</u>. </p>
<p><a href="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake3.png"><img src="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake3-300x145.png" alt="CakePhp bake step 3 - Installation result" title="cake_bake3" width="300" height="145" class="size-medium wp-image-123" /></a></p>
<p>Do we have the same result?</p>
<p>There were 3 things that happened here in the background. </p>
<ul>
<li>In mylibrary/app/config/core.php, the Security.salt was modified</li>
<li>mylibrary/app/config/database.php was created</li>
<li>In mylibrary/app/webroot/index.php, CAKE_CORE_INCLUDE_PATH was changed to the absolute path of your cake core library, in my case &#8220;E:www\minilib&#8221; because this is what I entered in my Path settings (remember this <a rel="nofollow" href="http://www.webdevelopment2.com/cakephp-bake-baking-models-controllers-views-cakephp-12/">tutorial</a>?) So with this, you have a <strong>centralized cakephp core library</strong>.</li>
</ul>
<p>There you have it, a new cakephp project! Let&#8217;s proceed.</p>
<p><b>Step 3: Create models, controllers and views</b><br />
Next step is to create our library application. Again, type <strong>cake bake</strong> in your command line. The <strong>Interactive Bake Shell</strong> will appear to ask for more directions. You must ofcourse create first your models, then controllers and finally views. Afterwards, you should have the following files like mine:</p>
<p><a href="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake4.png"><img src="http://cakephp.prometsupport.com/wp-content/uploads/2008/10/cake_bake4-129x300.png" alt="CakePhp Bake Step 3 - result" title="cake_bake4" width="129" height="300" class="size-medium wp-image-127" /></a></p>
<p>If you already have that, congratulations! Your done! <img src='http://cakephp.prometsupport.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Visit the Books page in <u>http://localhost/mylibrary/books/</u> to start adding your data.</p>
<p><strong>More tricks you can try out</strong><br />
There are also shortcuts if you only want to create models<br />
<code lang="bash">cake bake model</code></p>
<p>or controllers<br />
<code lang="bash">cake bake controller</code></p>
<p>or views<br />
<code lang="bash">cake bake view</code></p>
<p>For the next post, I&#8217;ll tackle how to set up different authentication components. Till next time. Happy Baking!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/learn-how-to-bake-cakephp-app/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Learn Containable Behavior by Example</title>
		<link>http://cakephp.prometsupport.com/2008/learn-containable-behavior-by-example/</link>
		<comments>http://cakephp.prometsupport.com/2008/learn-containable-behavior-by-example/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 07:58:49 +0000</pubDate>
		<dc:creator>rachel</dc:creator>
				<category><![CDATA[Associations]]></category>
		<category><![CDATA[Behaviors]]></category>
		<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Tips & Tutorials]]></category>
		<category><![CDATA[containable]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/?p=44</guid>
		<description><![CDATA[In cakephp, adding relationships is easy. We just have to declare the hasOne, belongsTo, hasMany and the famous HABTM relationship to do all the dirty work of joining tables. But declaring them all at once could lead to a slow page. In version 1.1, what we do is utilize the bindModel() and unbindModel(). We do [...]]]></description>
			<content:encoded><![CDATA[<p>In cakephp, adding relationships is easy. We just have to declare the hasOne, belongsTo, hasMany and the famous HABTM relationship to do all the dirty work of joining tables. But declaring them all at once could lead to a slow page.</p>
<p>In version 1.1, what we do is utilize the <a href="http://cakephp.prometsupport.com/2008/binding-ur-models-d-easy-way/">bindModel() and unbindModel()</a>. We do not declare all associations in the Model class yet. This was a good solution. I was looking for this option in version 1.2 and I found the Containable Behavior. Studying containable was a little rough before but there are documents now that are really helpful.<br />
<span id="more-44"></span></p>
<ul>
<li><a href="http://book.cakephp.org/view/474/Containable">Cakephp Book: Containable</a></li>
<li><a href="http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/">CakeBaker: New Core Behavior &#8211; Containable</a></li>
<li><a href="http://www.studiocanaria.com/articles/cakephp_containable_behavior">StudioCanaria: Cakephp Containable Behavior</a></li>
</ul>
<p>Today, I&#8217;ll be showing you how to use Containable in pagination and in regular find method. You must have a fair understanding of the behavior so I suggest you read the above articles first. If you are ready, follow the instructions below:</p>
<ol>
<li>Download the latest 1.2 release of cake. As of this writing, I tested it in cake_1.2.0.7296-rc2. Do the usual cake installation procedures.</li>
<li><a href="http://cakephp.prometsupport.com/wp-content/uploads/2008/09/containable_by_example.zip">Download this file</a> and unzip. It must contain an &#8220;app&#8221; folder</li>
<li>Replace the /app from #1 with the /app from #2 but leave the config file of #1.</li>
<li>Use the /app/class.sql to setup your database</li>
</ol>
<p>The idea of the sample is taken from a virtual school application. So we have Departments, Courses, Classes, Students and Teachers, Students Comments on Class and Students Ratings on Class. The following is an explanation of tables declared in class.sql so you can follow the relationships:</p>
<table style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="10" width="100%">
<tbody>
<tr valign="top">
<th width="20%">TABLE</th>
<th>RELATIONSHIP</th>
</tr>
<tr valign="top">
<td>department</td>
<td>has many courses</td>
</tr>
<tr valign="top">
<td>courses</td>
<td>has many classes<br />
belongsto departments</td>
</tr>
<tr valign="top">
<td>classes</td>
<td>belongs to courses<br />
belongs to teacher<br />
has many comments<br />
has many ratings</td>
</tr>
<tr valign="top">
<td>teachers</td>
<td>has many classes</td>
</tr>
<tr valign="top">
<td>ratings</td>
<td>belongs to class<br />
belongs to student</td>
</tr>
<tr valign="top">
<td>comments</td>
<td>belongs to class<br />
belongs to student</td>
</tr>
<tr valign="top">
<td>students</td>
<td>has many comments<br />
has many ratings</td>
</tr>
</tbody>
</table>
<h2>Exampe1: List of Classes</h2>
<p>What we will do is get only the basic information for the list of classes. Those includes:</p>
<ul>
<li>Class title</li>
<li>Course it belongs to</li>
<li>Department it belongs to</li>
<li>Teacher name</li>
</ul>
<p>It will look like this (replace the http://localhost with your local address)<br />

http://localhost/cake/my_classes/index</p>

<p>Let&#8217;s compare the recursive and containable method.</p>
<p><strong>Using The Recursive Method</strong><br />
Check the MyClassesController::unfiltered_result() for your reference. First try is I added the ffg line<br />
<code lang="php">$this->MyClass->recursive = 1; </code><br />
but the problem is that I could not get the Department name. Then I tried<br />
<code lang="php">$this->MyClass->recursive = 2; </code><br />
and there I have all the information I need. The problem is that there are just to many data I do not need. Another option is to use the the paginate fields filter. Try adding this:<br />
<code lang="php">$this->paginate['MyClass']['fields'] = array( 'Course.title', 'MyClass.title' );</code></p>
<p>The result? Check it for yourself in http://localhost/cake/my_classes/unfiltered_result</p>
<p><strong>Using Containable Behavior</strong><br />
If you look at MyClassesController::index2(), you would see the ffg:<br />
<code lang="php"><br />
        $this->paginate['MyClass']['contain'] = array (<br />
            'Teacher',<br />
            'Course' => array (<br />
                'Department' => array (<br />
                    'fields' => array (<br />
                        'Department.title',<br />
                        'Department.id'<br />
                    )<br />
                )<br />
            )<br />
        );<br />
</code><br />
That basically tells cake to find the Class Teacher and return all fields, the course it belongs to and return all the fields and finally the course&#8217; Department title and ID. Now run this http://localhost/cake/my_classes/filtered_result and compare the result with the previous example. It became cleaner isn&#8217;t it?</p>
<p>With Containable, you can specify which tables to include and what fields to include each table. You can also add order and limit filters and also conditions. It took me a while to grasp the format because at first glance it is a bit difficult to follow. I use the following format:</p>
<p><code lang="php"><br />
$this->Model0->contain( array(<br />
 'Model1' => array (<br />
 'fields' 	 => array( 'modelField1', 'modelField2' ),<br />
 'conditions' => array( 'your condition here' ),<br />
 'order' 	 => array( 'id' => 'asc' ),<br />
 ),<br />
 'Model2',<br />
 'Model2'<br />
 )<br />
)<br />
</code></p>
<h2>Example2: Class View</h2>
<p>This is just to show you a more complicated containable query. We want to get more information about the class. That includes:</p>
<ul>
<li>Class title</li>
<li>Course it belongs to</li>
<li>Department it belongs to</li>
<li>Teacher name</li>
<li><strong>Student comments that were approved and student name</strong></li>
<li><strong>Student ratings that were approved and student name</strong></li>
</ul>
<p>We can achieve the desired results using recursive but then again we will be wasting so much process time. In containable, we&#8217;ll just have to declare what we want.</p>
<p><code lang="php"><br />
        $this->MyClass->contain( array(<br />
            'Teacher',<br />
            'Rating'     => array(<br />
                'Student',<br />
                'order' => array( 'created' => 'desc' ),<br />
                'conditions' => array( 'approved' => 1 )<br />
            ),<br />
            'Comment'    => array(<br />
                'Student',<br />
                'order' => array( 'RAND()' ),<br />
                'limit' => 3 ,<br />
                'conditions' => array( 'approved' => 1 )<br />
            ),<br />
            'Course'     => array(<br />
                'Department' => array(<br />
                    'fields' => array(<br />
                        'Department.title',<br />
                        'Department.id'<br />
                    )<br />
                )<br />
            )<br />
            )<br />
        );<br />
</code></p>
<p>Can you see the format now? Play around with the codes and check their results to get more comfortable with it. Happy Baking!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/learn-containable-behavior-by-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use Model-&gt;create()</title>
		<link>http://cakephp.prometsupport.com/2008/use-model-create/</link>
		<comments>http://cakephp.prometsupport.com/2008/use-model-create/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 05:35:23 +0000</pubDate>
		<dc:creator>rolan</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/?p=37</guid>
		<description><![CDATA[From now on, I&#8217;ll always use Model-&#62;create() before saving new data. I&#8217;ve been using Model-&#62;create() for a series Model-&#62;save() calls (like in a loop) to initialize the model class for saving new information. But when I only need to do a single call to save(), I no longer call create() assuming that I&#8217;m starting with [...]]]></description>
			<content:encoded><![CDATA[<p>From now on, I&#8217;ll always use Model-&gt;create() before saving new data.</p>
<p>I&#8217;ve been using Model-&gt;create() for a series Model-&gt;save() calls (like in a loop) to initialize the model class for saving new information. But when I only need to do a single call to save(), I no longer call create() assuming that I&#8217;m starting with a new set of information. I was always able to get away with it until I had this bug that annoyed me for a few hours.</p>
<p>Long story short, I learned something: not only when doing multiple calls to <em>Model-&gt;save()</em>, you should also call <em>Model-&gt;create()</em> before saving if a previous call to <em>Model-&gt;read()</em> was made. Or better yet, <strong>always call Model-&gt;create() whenever you are about to save new data</strong>. There are cases the previous calls to save and read made are not that obvious, like in the beforeFilter() callbacks of the controller (or the parent::beforeFilter(), like in my case).</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/use-model-create/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery star rating problem with brackets []</title>
		<link>http://cakephp.prometsupport.com/2008/jquery-star-rating-problem-with-brackets/</link>
		<comments>http://cakephp.prometsupport.com/2008/jquery-star-rating-problem-with-brackets/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 10:54:23 +0000</pubDate>
		<dc:creator>rachel</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[bug fixes]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[star rating]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/jquery-star-rating-problem-with-brackets/</guid>
		<description><![CDATA[If you used the star rating plugin of jQuery in cakePHP, you might experienced that the hover effects are not working properly. This is because one of the class name used to identify the buttons uses the radio button name. This will be a problem in cakephp because we use brackets in names. In order [...]]]></description>
			<content:encoded><![CDATA[<p>If you used the <a href="http://plugins.jquery.com/project/MultipleFriendlyStarRating">star rating plugin of jQuery</a> in cakePHP, you might experienced that the hover effects are not working properly. This is because one of the class name used to identify the buttons uses the radio button name. This will be a problem in cakephp because we use brackets in names.</p>
<p><code lang="html"></p>
<input type="radio" name="data[Model][field]" class="star" />
</code></p>
<p>In order to fix that, we need to remove them. Here is quick fix. Open file <code>jquery.rating.js</code>:</p>
<p>from (line 97):<br />
<code lang="javascript"><br />
// grouping:<br />
  var n = this.name;<br />
</code></p>
<p>to:<br />
<code lang="javascript"><br />
// grouping:<br />
  var real_name = this.name;<br />
  var n = real_name.replace(/[^A-Za-z0-9_\-]/g, '-'); // remove unwanted characters<br />
</code></p>
<p>from (line 108):<br />
<code lang="javascript"><br />
$.rating.groups[n].valueElem = $('<br />
<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');<br />
</code></p>
<p>to:<br />
<code lang="javascript"><br />
$.rating.groups[n].valueElem = $('<br />
<input type="hidden" name="' + real_name + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');</code></p>
<p>I have <a href="http://plugins.jquery.com/node/3365">reported this in the bugtracker</a> and I hope it will be included in the next release.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/jquery-star-rating-problem-with-brackets/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Making Clickable Images on CakePHP</title>
		<link>http://cakephp.prometsupport.com/2008/making-clickable-images-on-cakephp/</link>
		<comments>http://cakephp.prometsupport.com/2008/making-clickable-images-on-cakephp/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 08:14:43 +0000</pubDate>
		<dc:creator>cyrose</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Helpers]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/making-clickable-images-on-cakephp/</guid>
		<description><![CDATA[Hello again, Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here&#8217;s how: 1. We will use HTML [...]]]></description>
			<content:encoded><![CDATA[<p>Hello again,</p>
<p>Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here&#8217;s how:</p>
<p>1. We will use HTML Helpers Image and Link, and we shall combine this 2.</p>
<p>2. For Image,</p>
<p>Syntax:</p>
<p>$html-&gt;image(string <em>$path</em>, array <em>$htmlAttributes</em>, boolean <em>$return = false);</em></p>
<p>Example:</p>
<p>$html-&gt;image(&#8216;/img/images/cancel.png&#8217;, array(&#8216;class&#8217; =&gt; &#8216;save_button&#8217;));</p>
<p>3. For Link,</p>
<p>Syntax:</p>
<p>$html-&gt;link(string <em>$title, </em>string <em>$url, </em>array <em>$htmlAttributes, </em>string <em>$confirmMessage = false, </em>boolean <em>$escapeTitle = true, </em>boolean <em>$return = false</em>);</p>
<p>Example:</p>
<p>$html-&gt;link(&#8216;SAVE&#8217;, &#8216;/registers&#8217;, array(), false, false, false);</p>
<p>4. So to make an image clickable,</p>
<p>&lt;?php echo $html-&gt;link($html-&gt;image(&#8216;/img/images/cancel.png&#8217;,array(&#8216;class&#8217; =&gt; &#8216;save_button&#8217;)), &#8216;/registers&#8217;, array(), false, false, false); ?&gt;</p>
<p>That&#8217;s it. I hope this will help you in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/making-clickable-images-on-cakephp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setting Frontpage in CakePHP</title>
		<link>http://cakephp.prometsupport.com/2008/setting-frontpage-in-cakephp/</link>
		<comments>http://cakephp.prometsupport.com/2008/setting-frontpage-in-cakephp/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 01:21:12 +0000</pubDate>
		<dc:creator>cyrose</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[cakePHP websites]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/07/21/setting-frontpage-in-cakephp/</guid>
		<description><![CDATA[Hello again readers, I have another topic for newbies like me. I know this will help you. And this is very, very easy and it&#8217;s a common thing to do when developing websites. It&#8217;s establishing a homepage. Here&#8217;s how and this won&#8217;t take long. 1. Code your desired design. This does not require you to [...]]]></description>
			<content:encoded><![CDATA[<p>Hello again readers,</p>
<p>I have another topic for newbies like me. I know this will help you. And this is very, very easy and it&#8217;s a common thing to do when developing websites. It&#8217;s establishing a homepage. Here&#8217;s how and this won&#8217;t take long.</p>
<p>1. Code your desired design. This does not require you to complete the entire html tags. Just the contents inside &lt;body&gt;&lt;/body&gt; would be fine.</p>
<p>2. Then save it as home.ctp and upload to app/views/pages.</p>
<p>And that&#8217;s it. You can now check your new homepage design.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/setting-frontpage-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting Your Page Layout in CakePHP</title>
		<link>http://cakephp.prometsupport.com/2008/setting-your-page-layout-in-cakephp/</link>
		<comments>http://cakephp.prometsupport.com/2008/setting-your-page-layout-in-cakephp/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 07:43:48 +0000</pubDate>
		<dc:creator>cyrose</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[cakePHP websites]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/07/21/setting-your-page-layout-in-cakephp/</guid>
		<description><![CDATA[I am not a pro in CakePHP, and in fact, i am just a beginner who wanted to explore it. When I was on my way to creating my goal, I stumbled upon a problem on how to change and then set the new page layout to be used. Honestly, the problem didn&#8217;t took me [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a pro in CakePHP, and in fact, i am just a beginner who wanted to explore it. When I was on my way to creating my goal, I stumbled upon a problem on how to change and then set the new page layout to be used. Honestly, the problem didn&#8217;t took me long to solve. I was lucky to have read the manual on the official site. So to cut the long story short, here is the list of steps which I did to come up with my new and first page layout on my CakePHP inspired website and you might consider following this little manual, too.</p>
<p>1. First, design the layout that you wanted to implement and use. Assuming we have the simple code below as your desired page layout.<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>2. After having established the base, let us now put the code that will show the title of your page. We will use $title_for_layout to do the job. So your head section will now look like this:<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;?php echo $title_for_layout?&gt;&lt;/title&gt;<br />
&lt;/head&gt;</p>
<p>3. Next inline would be displaying the contents. We will use $content_for_layout. It will tell CakePHP where to place the code for your views. Our code now will look like this one.<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;?php echo $title_for_layout?&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php echo $content_for_layout ?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>4. Then save it as app/views/layouts/default.ctp.</p>
<p>Next topic would be creating and using multitle layouts for single website. Please feel free to share your views which you think can help us beginners make a step higher on CakePHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/setting-your-page-layout-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CakePHP 1.2: Using Auth with ACL</title>
		<link>http://cakephp.prometsupport.com/2008/cakephp-12-using-auth-with-acl/</link>
		<comments>http://cakephp.prometsupport.com/2008/cakephp-12-using-auth-with-acl/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 09:05:27 +0000</pubDate>
		<dc:creator>rolan</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/07/16/cakephp-12-using-auth-with-acl/</guid>
		<description><![CDATA[A project we&#8217;re working on needed something to keep track of user activity and restrict parts of the application to certain users/groups. We are using CakePHP 1.2 and decided to use its built-in support for user authentication and access control list. Though each of them is nicely documented at the Cookbook, there wasn&#8217;t much info [...]]]></description>
			<content:encoded><![CDATA[<p>A project we&#8217;re working on needed something to keep track of user activity and restrict parts of the application to certain users/groups. We are using CakePHP 1.2 and decided to use its built-in support for user authentication and access control list. Though each of them is nicely documented at the Cookbook, there wasn&#8217;t much info or resource that shows how to put these two components to work together. Fortunately, we have found some nice tutorials/articles that helped us implement them into our application. Check out those links at the end.</p>
<h3>The Setup</h3>
<p>We want to restrict certain actions to certain types of users. But instead of assigning permissions to each user, we just divide users into groups and assign permission to groups. Users under the same group have the same set of permission.</p>
<p>For this example,&nbsp;&nbsp;we&#8217;ll be dividing users into groups namely: admin, editor and member.</p>
<h3>Setting up the database tables</h3>
<p>Users Table:<br />
<code lang="sql"><br />CREATE TABLE `users` (&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,<br />	`username` VARCHAR( 20 ) NOT NULL ,<br />	`password` VARCHAR( 50 ) NOT NULL ,<br />	`group_id` TINYINT( 2 ) NOT NULL DEFAULT '0',<br />	PRIMARY KEY ( `id` )) ENGINE = MYISAM ;</code><br />
Groups Table:<br />
<code lang="sql"><br />CREATE TABLE `groups` (</p>
<p>	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,<br />	`parent_id` INT UNSIGNED NOT NULL DEFAULT '0',<br />	`name` VARCHAR( 20 ) NOT NULL ,<br />	PRIMARY KEY ( `id` )<br />) ENGINE = MYISAM ;</code><br />
ACL Tables:<br />
The sql dump for the acl table can also be found at the app/config/sql folder of your application<br />
<code lang="sql"><br />CREATE TABLE acos (</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,<br />	parent_id INTEGER(10) DEFAULT NULL,<br />	model VARCHAR(255) DEFAULT '',<br />	foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,<br />	alias VARCHAR(255) DEFAULT '',<br />	lft INTEGER(10) DEFAULT NULL,<br />	rght INTEGER(10) DEFAULT NULL,<br />	PRIMARY KEY&nbsp;&nbsp;(id));</p>
<p>CREATE TABLE aros_acos (<br />	id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,<br />	aro_id INTEGER(10) UNSIGNED NOT NULL,<br />	aco_id INTEGER(10) UNSIGNED NOT NULL,<br />	_create CHAR(2) NOT NULL DEFAULT 0,<br />	_read CHAR(2) NOT NULL DEFAULT 0,<br />	_update CHAR(2) NOT NULL DEFAULT 0,<br />	_delete CHAR(2) NOT NULL DEFAULT 0,<br />	PRIMARY KEY(id)<br />);</p>
<p>CREATE TABLE aros (<br />	id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,<br />	parent_id INTEGER(10) DEFAULT NULL,<br />	model VARCHAR(255) DEFAULT '',<br />	foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,<br />	alias VARCHAR(255) DEFAULT '',<br />	lft INTEGER(10) DEFAULT NULL,<br />	rght INTEGER(10) DEFAULT NULL,<br />	PRIMARY KEY&nbsp;&nbsp;(id)</p>
<p>);</code></p>
<h3>Setting up the models</h3>
<p>After setting up the tables, we now move on to creating the models for our CakePHP application:</p>
<p>User model:<br />
<code lang="php"><br />uses('Sanitize');<br />class User extends AppModel {<br />	var $name = 'User';</p>
<p>	// Set the User model to use the ACL Behavior<br />	// This will take care of ACL-related things when working on<br />	// this model like adding/deleting the corresponding ARO node<br />	// when a user is added/deleted.<br />	var $actsAs = array('Acl');</p>
<p>	// Associate with the Group table<br />	var $belongsTo = array('Group');	</p>
<p>	function parentNode(){<br />		if (!$this->id) {<br />			return null;<br />		}</p>
<p>		$data = $this->read();</p>
<p>		if (!$data['User']['group_id']){<br />	&nbsp;&nbsp;		return null;<br />		} else {<br />	&nbsp;&nbsp;		return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);<br />		}<br />	}</p>
<p>	// Ok, even if the ACL behavior takes care of the insertion of the<br />	// corresponding ARO node, it doesn't save an alias so you have to<br />	// give one yourself. We'll be using the username for the alias.<br />	// We'll do this after a new user is saved/inserted, so do it inside<br />	// the model's afterSave function<br />&nbsp;&nbsp;	function afterSave($created) {</p>
<p>		// Do this if the save operation was an insertion/record creation<br />		// and not an update operation<br />&nbsp;&nbsp;		if($created) {<br />&nbsp;&nbsp;			// Ah, yes... we'll be needing the Sanitize component<br />&nbsp;&nbsp;			$sanitize = new Sanitize();	</p>
<p>			// Get the id of the inserted record<br />			$id = $this->getLastInsertID();</p>
<p>			// Instantiate an ARO model that will be used for updating<br />			// the ARO<br />			$aro = new Aro();</p>
<p>			// I'm using updateAll() instead of saveField()<br />			// Instead of querying the table to get the id of the<br />			// ARO node that corresponds to the user, I just provided<br />			// two field conditions whose combination uniquely identifies<br />			// the node (Model=> User, Foreign Key=> User id).</p>
<p>			// I don't know why it wasn't sanitizing my input and not<br />			// enclosing the input in quotes. I had to do it myself<br />			$aro->updateAll(<br />			array('alias'=>'\''.$sanitize->escape($this->data['User']['username']).'\''),<br />				array('Aro.model'=>'User', 'Aro.foreign_key'=>$id)<br />			);<br />		}<br />		return true;<br />	}<br />}</code><br />
The line:<br />
<code lang="php">var $actsAs = array('Acl');</code><br />
Sets the model to use CakePHP built-in ACL behavior. This will take care of ACL-related things when working on this model like adding/deleting the corresponding ARO node when a user is added/deleted.</p>
<p>When using the ACL Behavior, you need to provide a parentNode() method in your model. The parentNode() method returns the id of the parent of the current acl node. A tree structure is used to implement ACL, so you can either directly assign permission to a node or just allow a node to inherit the permissions of its parent.</p>
<p>I found out from Geoff&#8217;s blog (LemonCake) that the key to using groups for user permission is to <em>set the user aros as children of the a group aro.</em> You can do this inside the models parentNode() method:</p>
<p>Group Model:<br />
<code lang="php"><br />// Okay, I won't be commenting on this since this almost the same<br />// as what you can see from the user model definition</p>
<p>uses('Sanitize');<br />class Group extends AppModel {<br />	var $name = 'Group';<br />	var $actsAs = array('Acl');</p>
<p>	function parentNode(){<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	if (!$this->id) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;		&nbsp;&nbsp;&nbsp;&nbsp;	return null;<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	}<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	$data = $this->read();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	if (!$data['Group']['parent_id']){<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;		return null;<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;		return $data['Group']['parent_id'];<br />&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;	}<br />&nbsp;&nbsp;	}</p>
<p>&nbsp;&nbsp;	function afterSave($created) {<br />&nbsp;&nbsp;		if($created) {<br />&nbsp;&nbsp;			$sanitize = new Sanitize();	</p>
<p>			$id = $this->getLastInsertID();</p>
<p>			$aro = new Aro();</p>
<p>			$aro->updateAll(<br />				array('alias'=>'\''.$sanitize->escape($this->data['Group']['name']).'\''),<br />				array('Aro.model'=>'Group', 'Aro.foreign_key'=>$id)<br />				);<br />		}<br />		return true;<br />	}<br />}</code></p>
<h3>Setting up the controllers</h3>
<p>Okay now, let&#8217;s keep the code short. We won&#8217;t provide any user registration here, just a way of logging users in and out of the application.</p>
<p>users_controller.php:<br />
<code lang="php"><br />class UsersController extends AppController {<br />	var $name = 'Users';<br />	// We will be using the Acl and Auth component<br />	// The order you declare the components is<br />	// important. Acl first before Auth or you<br />	// will get an error message.<br />	var $components = array('Acl', 'Auth');</p>
<p>	// This is how complicated the login part<br />	// gets when using the auth component.<br />	function login() {<br />	}</p>
<p>	// ... and the logout part<br />	function logout() {<br />		$this->redirect($this->Auth->logout());<br />	}</p>
<p>	function beforeFilter() {<br />		$this->Auth->logoutRedirect = array(<br />			'admin' => false,<br />			'controller' => 'pages',<br />			'action' => 'index'<br />		);<br />	}</p>
<p>}</code><br />
Now that takes care of the user authentication. To use Auth w/ ACL in our controllers, we first need to include the components (of course!). Make sure that Acl goes before the Auth component or else, you&#8217;ll get an error message.<br />
<code lang="php"><br /> var $components = array('Acl', 'Auth');</code><br />
Then, we need to set the Auth component to treat the controller and actions as our access control objects. Inside the beforeFilter() method:<br />
<code lang="php"><br /> function beforeFilter()<br /> {<br /> 	$this->Auth->authorize = 'actions';<br /> }</code></p>
<h3>Setting Up AROs, ACOs and Permissions:</h3>
<p>Our AROs will be the users and groups. Since our user and group models already use the ACL behavior, we no longer have to worry creating AROs for them- they are already created when a new user or group is added. We only have to deal with creating ACOs. If you&#8217;ve already read the part of the manual about access control lists, you&#8217;ll find out that adding an ACO is just like saving data using models. You just need to specify the name of the controller/action as its alias and its parent id.<br />
<code lang="php"><br /> 	$aco = new Aco();<br /> 	$aco->create();</p>
<p> 	$aco->save(array(<br /> 	&nbsp;&nbsp; 'model'=>null,<br /> 	&nbsp;&nbsp; 'foreign_key'=>null,<br /> 	&nbsp;&nbsp; 'parent_id'=> $parentIdIfAny,<br /> 	&nbsp;&nbsp; 'alias'=> $nameOfControllerOrAction<br /> 	));</code><br />
You might want to have a root node where all default permissions will be based upon. Then this node will contain child nodes, which will be our controller names. Then each controller will have action names as child nodes.<br />
<code><br />Controller<br />&nbsp;&nbsp;&nbsp;&nbsp; |- Pages<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;|- index<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;|- about<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;|- contact<br />&nbsp;&nbsp;&nbsp;&nbsp; |- Articles<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|- index<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|- view<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|- add<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|- edit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|- delete</code><br />
To assign permissions, use the allow() and deny() methods of the ACL component. These methods takes at least 2 parameters: first is the ARO and second is the ACO. We could reference an ARO/ACO node using its alias or by providing an array of field conditions that uniquely describes the node.<br />
<code lang="php"><br />$this->Acl->allow(array('model'=>'Group', 'foreign_key'=>$groupId), $nameOfControllerOrAction);</code><br />
Since it is very likely that different controllers to have the same action names (thus making their alias non-unique and cause ambiguity), we can specify the path to the node using slashes (/).<br />
<code lang="php"><br />$this->Acl->allow(array('model'=>'Group', 'foreign_key'=>$groupId), 'Pages/index');<br />$this->Acl->allow(array('model'=>'Group', 'foreign_key'=>$anotherGroupId), 'Articles/index');</code><br />
You can deny all permissions on the root node (in this case, the &#8216;Controller&#8217;) to set default permissions that will be inherited by all the controllers. Then grant permission per controller or per action.</p>
<h3>The Test Run:</h3>
<p>I provided a simple app demo for download (<a href="http://cakephp.prometsupport.com/wp-content/uploads/2009/02/acl_demo.zip">acl_demo.zip</a>).<br />
1) Extract the contents of the zip file.<br />
2) Run the sql file found inside the models folder<br />
3) Edit the content (ROOT, APP_DIR and CAKE_CORE_INCLUDE_PATH paths) of index.php under the webroot folder according to you CakePHP setup<br />
4) Access the index page of the app (ex: http://localhost/acl/) and click the setup button. Take note of the username and password of the accounts that will be created.<br />
5) Login and test the application. Members page should only be accessible to members and admin. Editors page to editors and admin. Administrators page to administrator only.</p>
<p>Errors, corrections or suggestions? Feel free to leave a comment.</p>
<p>Sources:<br />
http://manual.cakephp.org/view/171/access-control-lists<br />
http://manual.cakephp.org/view/172/authentication<br />
http://lemoncake.wordpress.com/2007/07/15/using-aclbehavior-in-cakephp-12/<br />
http://lemoncake.wordpress.com/2007/07/19/acl-with-groups/<br />

http://aranworld.com/article/161/cakephp-acl-tutorial-what-is-it</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/cakephp-12-using-auth-with-acl/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Tip: use CakePHP Route::url() for your URLs</title>
		<link>http://cakephp.prometsupport.com/2008/tip-use-cakephp-routeurl-for-your-urls/</link>
		<comments>http://cakephp.prometsupport.com/2008/tip-use-cakephp-routeurl-for-your-urls/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 07:29:24 +0000</pubDate>
		<dc:creator>rachel</dc:creator>
				<category><![CDATA[CakePHP 1.2]]></category>
		<category><![CDATA[Tips & Tutorials]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[router]]></category>

		<guid isPermaLink="false">http://cakephp.prometsupport.com/2008/07/11/tip-use-cakephp-routeurl-for-your-urls/</guid>
		<description><![CDATA[Routing is one of the amazing features of CakePHP because it makes the urls beautiful. We use this most of the time and last time, I blogged about the helper to shortcut ones typing when using the HTML helper. Overtime, I realize how helpful it can be. Read on. Always use array when passing parameters [...]]]></description>
			<content:encoded><![CDATA[<p>Routing is one of the amazing features of CakePHP because it makes the urls beautiful. We use this most of the time and last time, I <a href="/2008/05/28/convenient-html-link/">blogged</a> about the helper to shortcut ones typing when using the HTML helper. Overtime, I realize how helpful it can be. Read on.</p>
<p>Always use array when passing parameters when creating a link or using Router::url(), it will save you time in the future. Why? Consider this scenario:</p>
<p>You created a controller <i>/users/register</i> and in your code and you added this<br />
<code lang="php"><br />
<?php echo $html->link('User Registration', '/users/register')?><br />
</code></p>
<p>Then your group or your boss decided to use a better name <i>/register</i>. Your initial thought would be to replace all those texts to those new ones, isn&#8217;t it? There is a better approach. Try the ffg:</p>
<p>In /config/router.php<br />
<code lang="php"><br />
<?php Router::connect('/register',	array('controller'=>'users','action'=>'register'));  ?><br />
</code></p>
<p>In your view:<br />
<code lang="php"><br />
<?php echo $html->link('Registration', array('controller'=>'users','action'=>'register'))?><br />
</code></p>
<p>the HTML helper uses Router::url() in its link function and the Router class magically converts array parameters to what you stated in your config.  In writing urls, we have to be consistent because it can be bad for SEO when you have too many urls pointing to the same location.</p>
<p>Although the above works beautifully but it can be a tedious job. I wrote not long ago about the <a href="/2008/05/28/convenient-html-link/">html helper</a> that could make this approach easier so you could write the ffg in your view. </p>
<p><code lang="php"><br />
<?php echo $html->link('Registration', url( 'users', 'register', null, 'teacher' ))?><br />
</code></p>
<p>It saves a few characters!</p>
<p>From the last post, I refactored it  and placed it in the bootstrap so I can call it anywhere (got that idea from the google groups). </p>
<p>Here it is:<br />
<code lang="php"><br />
    function url() {<br />
        $args = func_get_args();<br />
        $count = func_num_args();</p>
<p>        if ( $count == 1 ) {<br />
            if ( is_array( $args[0] ) ) {<br />
                $args = $args[0];<br />
                $count = count($args);<br />
            } else {<br />
                return $args[0];<br />
            }<br />
        }</p>
<p>        $short_keys = array(<br />
            0 => 'controller',<br />
            1 => 'action',<br />
            2 => 'plugin',<br />
            'c' => 'controller',<br />
            'a' => 'action',<br />
            'p' => 'plugin',<br />
        );</p>
<p>        foreach ( $short_keys as $short_name => $long_name ) {</p>
<p>            if ( isset( $args[$short_name] ) ) {<br />
                $args[$long_name] = $args[$short_name];<br />
                unset( $args[$short_name] );<br />
            }</p>
<p>        }</p>
<p>        // Need to explicitly assign plugin key<br />
        if ( !isset( $args['plugin'] ) ) $args['plugin'] = null;<br />
        if ( !isset( $args['action'] ) ) $args['action'] = 'index';<br />
        if ( !isset( $args['admin'] ) ) $args['admin'] = false;</p>
<p>        $routing = Configure::read('Routing.admin');<br />
        if ( preg_match( "/^{$routing}_/", $args['action'] ) &#038;&#038; $routing ) {<br />
            $args['admin'] = true;<br />
            $args['action'] = substr( $args['action'], strlen($routing) + 1 );<br />
        }</p>
<p>        return $args;<br />
    }<br />
</code></p>
<p>The function above could take an array OR any number of string parameters.<br />
<code lang="php"><br />
url ( 'controller', 'action', 'plugin_name', ...[more params here] )<br />
url ( array( 'c' => 'controller', 'a' => 'action', 'p' => 'plugin' ) )<br />
</code></p>
<p>The first one is strict for the first 3 parameters. The latter can be written in any order as you like. I also added support for <a href="http://www.sanisoft.com/blog/2008/04/04/the-prefix-automagic-in-cakephp-routing/">prefix routing</a> such as admin_*. So you can write:<br />
<code lang="php"><br />
url ( 'controller', 'admin_action', 'plugin_name', ...[more params here] )<br />
url ( array( 'c' => 'controller', 'a' => 'admin_action', 'p' => 'plugin' ) )<br />
</code></p>
<p><i><a href="http://api.cakephp.org/class_router.html#73cfb34ccc4dae2932041a130711ac05">Router::parse()</a></i> can also be used instead of <i>url()</i> function but the latter is faster. </p>
<p>That&#8217;s it. Happy Baking!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.prometsupport.com/2008/tip-use-cakephp-routeurl-for-your-urls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
