<?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>Farrworks &#187; Development</title>
	<atom:link href="http://farrworks.com/category/tech/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://farrworks.com</link>
	<description>Technology, Work, Life, Play, and everything else in between the ears of an Ian...</description>
	<lastBuildDate>Fri, 26 Feb 2010 22:17:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Understanding and escaping the dreaded Security Component Blackhole</title>
		<link>http://farrworks.com/2010/02/understanding-and-escaping-the-dreaded-security-component-blackhole/</link>
		<comments>http://farrworks.com/2010/02/understanding-and-escaping-the-dreaded-security-component-blackhole/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 22:09:09 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=216</guid>
		<description><![CDATA[So, you have a Form that you built in your CakePHP view and messing around with it using some javascript, and all of a sudden&#8230;.pooof&#8230;.the form won&#8217;t post anymore as the Security Component blackholes it. What did you do? How/what happened? Where do you start? Do you just disable the security plugin? Do you have [...]]]></description>
			<content:encoded><![CDATA[<p>So, you have a Form that you built in your CakePHP view and messing around with it using some javascript, and all of a sudden&#8230;.pooof&#8230;.the form won&#8217;t post anymore as the Security Component blackholes it. What did you do? How/what happened? Where do you start? Do you just disable the security plugin? Do you have other options? Well you are in luck, as I just finished a rather lengthy debugging process of just this, and have written below how things work in a fair amount of detail. Hopefully this will save others some pain.<br />
<span id="more-216"></span><br />
Alright, let&#8217;s get started right away.</p>
<p>You know that something in your form is blackholing, but don&#8217;t know what caused it &#8211; right? so let&#8217;s start from the beginning. How does the FormHelper and SecurityComponent work? how does it do it&#8217;s magic?</p>
<p>Well, you use the FormHelper to make your forms, and each time you insert a field, the FormHelper records it, and adds it to a &#8216;master list&#8217;, a $fields array in the form helper. Each type of field does something a little different, but basically, as long as the security component is included (in your app_controller or your controller), then by default, all fields that the FormHelper adds are &#8220;secured&#8221;.</p>
<p>Now, there are 2 different ways that the FormHelper secures form fields. On most fields, it secures just the fieldname, but on hidden form fields, it secures the fieldname <em><strong>and</strong></em> it&#8217;s value &#8211; this is called &#8220;locking&#8221; the field. This is important, as you will see in the example later. Securing just the fieldname means that all the form fieldnames must remain the same. None can be added, or removed, or renamed. All fieldnames must remain the same and can&#8217;t be changed. When you &#8220;lock&#8221; a form field. It&#8217;s name and value must remain the same.</p>
<p>Understanding that, let&#8217;s talk about how it secures things? how does it work? OK, we know that all form fields to be secured (either by locking it, or just securing the fieldname) are part of a master list in the FormHelper&#8217;s $fields property. When you call $form->end() in your view, it iterates through this array, and all form fields that should be secured &#8211; including the ones that should be &#8220;locked&#8221; are added to an array, and then a hash is generated from that array. That hash is stored in a hidden form element in that form (as [_Token][fields]). Now the [_Token][fields] contains the hash, and all the fields that were &#8220;locked&#8221; in an encoded format (rot13), which is serialized. The form also gets a [_Token][key] generated which is stored in the users session.</p>
<p>Now that the form is &#8220;tattooed&#8221; with the secure hash, it&#8217;s pretty easy for the SecurityComponent to verify things. When a form gets posted, the security component basically compares the key stored in the users [_Token][key] session variable with the form&#8217;s [_Token][key] to make sure it&#8217;s the same. If it is, then it simply takes all the forms current fieldnames, un-serialzes/un-encodes the rot13 &#8220;locked&#8221; fieldnames which indicate which fields were locked (which fieldnames had which values), puts it all in a new array, and takes a new hash of the entire thing. If the hash is stored in the original forms [_Token][fields]match, and the newly created hash match, then it id assumed that the form hasn&#8217;t been tampered with and things are good. If it doesn&#8217;t match &#8211; then the form has been tampered with, and the request is blackholed.</p>
<p>OK &#8211; so far it&#8217;s pretty straight forward &#8211; but the big thing for me is that, by default, <strong>all</strong> hidden form fields are locked.</p>
<p>Now, imagine in your form, you have a typical &#8220;edit&#8221; form, which you are loading data dynamically into with your javascript framework of choice. Now, you update the hidden &#8220;id&#8221; field because it needs to be updated to reflect the new dataset that is loaded into the form &#8211; so that if it&#8217;s posted it updates the correct row.</p>
<p>Well, in this case, with the above understanding we know that the form <strong>will</strong> be blackholed because a hidden form field (which is locked by default) has been changed. when the form gets posted, the security component will generate a new hash with the form data that it received from the post, and the new hash will not be the same as the old hash. crap, what do we do?</p>
<p>Well it turns out that you can <strong>disable</strong> security for hidden fields. Now before I tell you how, I must tell you that this isn&#8217;t really a good idea, and I have proposed a better way which I will get too below. How do you disable a hidden field from being secured? Easy:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hidden</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Model.fieldname'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'security'</span><span style="color: #339933;">=&gt;</span>false<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Now, this still won&#8217;t work in our example? Why? Well, this disables that field entirely from the secure &#8220;hash&#8221;. It isn&#8217;t locked anymore, and it&#8217;s not secured/present in the FormHelpers $fields array that gets hashed. Maybe some of you are saying &#8220;AHA!&#8221;, and maybe still some of you don&#8217;t see it yet&#8230;well, what happens when the form is posted? What does the SecurityComponent see? it sees all posted fields and values, all of a sudden there is an extra field in there (the hidden field), and a different hash will be generated. Since there is now a hash mismatch, the request is blackholed. &#8220;AHHHHHHH&#8221; how do we get around that?</p>
<p>This is where the SecurityComponent&#8217;s disableFields property comes in. If you disable the security in hidden fields using the above method, you <strong>must</strong> also disable them in the SecurityComponent using the disabledFields property in your beforeFilter(). That way, when the form gets posted, the security component knows which fields to ignore when generating and comparing the hashes, and they will match&#8230;but is this good?</p>
<p>I have been reading around, and it seems that most people just disable the SecurityComponent when ajax comes into the picture. Now, I consider using the SecurityComponent&#8217;s disableFields property pretty much the same as effectively disabling the SecurityComponent &#8211; especailly in the above case.</p>
<p>Why? well, what happens in the beforeFilter? well,  it is executed before each and every action for that controller. That means if we tell the Security component to disable the &#8220;id&#8221; field, <strong>all</strong> forms for that controller will have all their ID fields vulnerable for tampering. Is that a good thing? I would say the answer to that is a big no.</p>
<p>What really is needed is a way to control the hidden fields. a way to say &#8220;secure the hidden field, but don&#8217;t lock it&#8221;. This way the value of that field can be changed, but the fieldname itself cant be. So that fieldname must be present and accounted for in the post. Also, if we had some of this control, we wouldn&#8217;t need to mess with the SecurityComponent&#8217;s disableFields property (or at least not as much) in these specific circumstances. This means that for specific instances, we could allow the hidden fields to have their values changed and still keep full security for all other forms for that controller. I would say that this is a much more secure method of dealing with things.</p>
<p>Now, this still isn&#8217;t the best, as this indeed doesn&#8217;t protect someone from changing the value of the hidden property &#8211; but you should also have other checks in place to safeguard against this (does the current user have the proper permissions to make this change?). But at least if we had this option in the FormHelper, then at least we could make that choice.</p>
<p>It turns out that to add this type of choice isn&#8217;t too hard, but, for now, it does require you to override the default FormHelper.</p>
<p>If you copy cake&#8217;s FormHelper into your view->helpers in your app directory, then all that is needed is to make the hidden method look like this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> hidden<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fieldName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$secure</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$secureValue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secure'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$secure</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secure'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secure'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secureValue'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$secureValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secureValue'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'secureValue'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_initInputField<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fieldName</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'secure'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fieldName</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'_method'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$model</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'_Token'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$secure</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$secureValue</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__secure<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fieldName</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'_method'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$model</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'_Token'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$secure</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$secureValue</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__secure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hidden'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_parseAttributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>if you do this, then on hidden form elements, you can pass an options array that has the following possibilities:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hidden</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Model.fieldname, array(&quot;secure&quot;=&gt;true,&quot;secureValue&quot;=&gt;false));</span></div></div>
<p>secure, and secureValue defaults to true, meaning that by default, hidden fields are locked. but if you change the secureValue to false, the hidden field will just be secured (meaning that the value is allowed to change, but the fieldname itself must be present and accounted for, but you should know that by now..right <img src='http://farrworks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<p>I did open a ticket at the lighthouse, so maybe one day that change will be included in the FormHelper&#8230;but until then, this work around is needed (or you have to still mess with the SecurityComponent&#8217;s disableFields property &#8211; and remember to pass the &#8217;secure&#8217;=>false option on hidden fields also, and &#8220;unlock&#8221; it for that entire controller).</p>
<p>Another option is to not use the form helpers hidden fields, and use the regular text input fields, then disable them/hide them with css/javascript. If you do it this way, then you do not need the FormHelper modification above, and as long as you don&#8217;t add/remove fields, your form will not get blackholed.</p>
<p>Hopefully now you have a better understanding of what types of changes will cause blackholes, and what options you have in dealing with them. If you rather have a patch for the above workaround, you can grab it from <a href="http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/399-formhelper-is-hardcoded-to-secure-hiddenfields-by-both-fieldname-and-value">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2010/02/understanding-and-escaping-the-dreaded-security-component-blackhole/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jquery Form Plugin clearForm() issue with CakePHP security component</title>
		<link>http://farrworks.com/2009/07/jquery-form-plugin-issue-with-cakephp-security-component/</link>
		<comments>http://farrworks.com/2009/07/jquery-form-plugin-issue-with-cakephp-security-component/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 14:32:35 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=202</guid>
		<description><![CDATA[This week I have had an issue where every time I cleared a form using JavaScript, CakePHP&#8217;s security component halt the processing and complained when posting it. I am using the jquery form plugin&#8217;s .clearForm() to clear the form, and found the issue, and work around.

At first I didn&#8217;t know where to start, the Security [...]]]></description>
			<content:encoded><![CDATA[<p>This week I have had an issue where every time I cleared a form using JavaScript, CakePHP&#8217;s security component halt the processing and complained when posting it. I am using the jquery form plugin&#8217;s .clearForm() to clear the form, and found the issue, and work around.<br />
<span id="more-202"></span></p>
<p>At first I didn&#8217;t know where to start, the Security component just was rejecting the post. so I started experimenting, and found that it only happened on select boxes. Clearing text or textarea fields were not an issue. After looking around a bit more, I found that version 2.21 of the jquery form plugin (and probably all other version) at around line 578 was changing the selected index of all select boxes to -1. Since -1 is not a valid option (option&#8217;s start at 0), the Security component was thinking that the form had been tampered with, and rejected the post.</p>
<p>A simple change in the clearFields() function (the clearForm() function calls the clearFields function for all form elements of type text, select and textarea) fixed this all up:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//original code:</span><br />
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tag <span style="color: #339933;">==</span> <span style="color: #3366CC;">'select'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selectedIndex</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//replace with:</span><br />
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tag <span style="color: #339933;">==</span> <span style="color: #3366CC;">'select'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selectedIndex</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span></div></div>
<p>I guess the important part here may not be about fixing the jquery form plugin, but more this: however you are clearing your form, if you run into issues with the Security component, make sure that on select boxes you are not assigning them invalid option indexes (-1 in the above case).</p>
<p>That&#8217;s it. Now the select box entries go back to the first option (option 0 &#8211; which is often blank anyways) when a &#8220;clear form&#8221; button is pressed, the Security component will accept the post &#8211; and everyone is happy <img src='http://farrworks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2009/07/jquery-form-plugin-issue-with-cakephp-security-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Tale of PHP IDE&#8217;s</title>
		<link>http://farrworks.com/2009/02/a-tale-of-php-ides/</link>
		<comments>http://farrworks.com/2009/02/a-tale-of-php-ides/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 06:22:23 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Banter]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=160</guid>
		<description><![CDATA[I have been an Ecipse PDT user for the last couple of years, and while I have gotten it to &#8220;work&#8221; with CakePHP, I have always found it a messy solution, as you have to &#8220;hack&#8221; up your sources pretty good in order for Eclipse to understand the CakePHP world.
While this does work, it is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been an Ecipse PDT user for the last couple of years, and while I have gotten it to &#8220;work&#8221; with CakePHP, I have always found it a messy solution, as you have to &#8220;hack&#8221; up your sources pretty good in order for Eclipse to understand the CakePHP world.</p>
<p>While this does work, it is not a pretty solution, is not easily manageable, and leaves a bad taste in my mouth, so I figured that there must be a better way&#8230;and there is with <a href="http://www.netbeans.org">Netbeans </a>!</p>
<p><span id="more-160"></span></p>
<p>So, off I go again seeing if there are any new developments in the PHP IDE arena these last 6 months or so, and what do I find&#8230;Netbeans for PHP. Because I have tried almost every other PHP IDE on the planet, but have never tried <a href="http://www.netbeans.org">Netbeans </a>(since it never really had good PHP support until recently)&#8230;I decide that this will be the week.</p>
<p>As I am downloading and installing the thing, I start browsing around to see if there are any tips for CakePHP integration. About 30 seconds later,  I find something &#8211; and it looks promising.</p>
<p>So, I load up my usual test project, make some modifications to the source&#8217;s comments so that Netbeans understands the Cake world, and what can I say &#8211; I was really, really, really floored. This worked MUCH better then anything I had ever used before &#8211; much, much better then I ever had with Eclipse, in a much cleaner, and more manageable way.</p>
<p>Before I start talking too much about Netbeans, let me just cover the issues that I had with Eclipse&#8217;s code completion with CakePHP. To get Eclipse to understand that $this->Model in your controller was a model, you had to add something like the following to your controller:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* @var ModelName<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$ModelName</span><span style="color: #339933;">;</span></div></div>
<p>Now, this doesn&#8217;t seem like a big deal at first, but once you realize that you have to do this for every component, helper, model that your controller uses, it gets a little nasty. Now, let&#8217;s just say that our $ModelName model has multiple relationships with other models. The CakePHP way is to access them as such:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ModelName</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">OtherModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>So, Eclipse knows about ModelName, and we have code completion for that. But it knows nothing about ModelName->OtherModel&#8230;no code completion, we are stuck. So off we go again adding more comment blocks to try and manage Eclipse.</p>
<p>Now, again, you multiply this by all of your application models, and you end up with a mess pretty quickly. This even gets worse.</p>
<p>For components, cakePHP uses a component array to define which components your controller will use. Let&#8217;s say that I have some core components that I will use in every controller. Instead of loading them up manually in each and every controller, it makes more sense to load them up in my AppController, where all the other controllers are derived from.</p>
<p>So, in your AppController you start adding the Eclipse @var code blocks for all the components so that Eclipse can figure out the code completion, and it works great&#8230; in your AppController at least. Next you open one of your other controllers and start typing $this->ComponentName->&#8230;.and nothing. No code completion again!! Eclipse, for whatever reason, can&#8217;t code complete an inherited @var comment block. Maybe I just did something wrong, but this never really worked well at all for me, at least not consistently.</p>
<p>Ok, so how do you get it working&#8230;well, you have to include the stupid @var comment blocks in each and every controller that you want code completion for&#8230;this is insane and is a complete mess.</p>
<p>You do this for all your Model&#8217;s, all the Model relationships, all the components, and then count how many lines of code in your entire project that was added just to make eclipse&#8217;s code completion work&#8230;it&#8217;s a lot. A lot of code, a lot of redundancy, and when you have to change things, it&#8217;s a lot of new code to add &#8211; simply stated, it&#8217;s a lot. Too much if you ask me.</p>
<p>Ok, so now I have talked about how all the Eclipse hacks are messy, how does Netbeans compare?</p>
<p>At first Netbeans seems to use a very similar method for helping it understand CakePHP&#8217;s world. You use @property javadoc comments in the codeblocks just before the class&#8217;s declaration, like so:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* @property ModelName $ModelName<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">Class</span> ModelNamesController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></div></div>
<p>So, now you have a single @property javadoc comment to tell Netbeans that $this->ModelName refers to the ModelName model for that controller, and code completion works great. So far so good. </p>
<p>At least this is just a single comment line, and I don&#8217;t need to declare a useless variable like I have to do with Eclipse. With Eclipse, I would have a comment block consisting of at least 1 line, but possibly 3 lines (/**, * @var, */) depending on the project&#8217;s source code formating policy, and then the actual useless var $name line. That&#8217;s either 2 or 4 lines of code to do Netbeans&#8217; 1 line of code. That&#8217;s at least a 50% improvement, not bad at all.</p>
<p>What about $this->ModelName->OtherModel-> code completion support? How do I get that to work?</p>
<p>Well, this is where Netbeans really starts to show it&#8217;s power. In the comment block that is just before your Model declaration, just add  the same @property for each model that it has a relationship with. Example:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* @property OtherModel $OtherModel<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">class</span> ModelName <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></div></div>
<p>That&#8217;s it. Again, a single line of code for each relationship that this model has. The best thing about this is that Netbeans, unlike Eclipse, properly understands inheritance when it comes to the @property javadoc comments. As soon as you do this in your Models, all of a sudden, in your controller, $this->MyModel->OtherModel-> has code completion&#8230;awesome. This never worked well with Eclipse, and I just got rid of a TON of code duplication all over the place with @var comment blocks to try and get Eclipse to work. Now I am really happy, as this is much more then a 50% improvement&#8230;</p>
<p>Now, what about components? Well, components are exactly the same thing. In my AppController&#8217;s comment block that is right above it&#8217;s class declaration (for all the common components that every controller uses), you just add an &#8216;@property ComponentNameComponent $ComponentName&#8217; line for every component that you want to use. Again, because Netbeans understands inheritance with these @property comments, they work in every controller &#8211; immediately. Wow.</p>
<p>Ok &#8211; now I am in heaven. I can get rid of all of these silly @var&#8217;s all over the place, which already cleans up the code a lot, and have a much cleaner, and controllable method of telling Netbeans about the CakePHP world.</p>
<p>At this point, I wanted to see how helpers in the views could get code completion, and this works pretty much exactly like Eclipse, so they are the same when it comes to helper code completion support. All you need is a file in a include directory, or somewhere in the &#8220;project&#8221; that has something like:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//this file does nothing, it's just so netbeans can code assist any of these</span><br />
<span style="color: #666666; font-style: italic;">//objects in all our views</span><br />
<br />
<span style="color: #000088;">$ajax</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AjaxHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FormHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$javascript</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JavascriptHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SessionHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TimeHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$pagination</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PaginationHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RssHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$paginator</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PaginatorHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>As long as Netbeans (or eclipse for that matter), can see this file, you get code completion for helpers in all your views. This is an OK work around, and I have no issues with this method.</p>
<p>Netbeans also has some really nice features out of the box:</p>
<ul>
<li>awesome refactoring support &#8211; very cool stuff (look into Ctrl-R)</li>
<li>searching with very cool &#8220;diff&#8221; like displays for all matches in the scrollbar area</li>
<li>great CSS code completion</li>
<li>awesome javascript support</li>
<li>support for multiple language code completion in a single file (ex: css -> javascript -> php)</li>
</ul>
<p>You add all this up, and I think that it will take a major problem Netbeans to get me back over to the Eclipse camp. </p>
<p>It is at least as good as Eclipse in most areas, and has a much cleaner and easier way of setting up code completion for PHP frameworks. It is also a no hastle-everything just works- installation, unlike Eclipse where you have to download a bunch of add-ons after you get it so that it can do the things you want&#8230;that&#8217;s if you remember which update site was needed to install the add-on&#8230;..that&#8217;s also a mess &#8211; but let&#8217;s not go there right now <img src='http://farrworks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>The Netbeans add-on&#8217;s are more along the lines of Jedit, where you have a single section in Netbeans to view all &#8220;stable&#8221; add-ons, and you can install them within Netbeans. No browsing around for a while trying to find something and figuring out how to install it like you have to with Eclipse. You can also download alpha/beta add-ons from the netbeans.org site easily, which then you can install them in netbeans with a couple of clicks. I think this is a much better way of handling add-ons.</p>
<p>So &#8211; I think I am a Netbeans convert&#8230;if you haven&#8217;t used it before, I think it deserves a shot.</p>
<p>If you have had similar (or dissimilar) experiences with Netbeans, I would love to hear your comments <img src='http://farrworks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2009/02/a-tale-of-php-ides/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using CakePHP &#8220;Parts&#8221; in Other Applications</title>
		<link>http://farrworks.com/2009/02/using-cakephp-components-in-other-applications/</link>
		<comments>http://farrworks.com/2009/02/using-cakephp-components-in-other-applications/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 17:22:00 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=136</guid>
		<description><![CDATA[So, you have some third party PHP based web application, and you want to somehow &#8220;link&#8221; it with your CakePHP site. Wouldn&#8217;t it be great if this other application could share some things with your Cake site, like use your existing security components to check if the current user is authorized to use this third [...]]]></description>
			<content:encoded><![CDATA[<p>So, you have some third party PHP based web application, and you want to somehow &#8220;link&#8221; it with your CakePHP site. Wouldn&#8217;t it be great if this other application could share some things with your Cake site, like use your existing security components to check if the current user is authorized to use this third party application, or have this third party application retrieve session information for the current user?</p>
<p>I had to do just this in one of my current projects. I used the <a href="http://kfm.verens.com/">kfm file manager</a>, and wanted to integrate it into a CakePHP web site as seemlessly as possible. I was mainly concerned with access and authorization as I wanted to use the same components/controllers that my CakePHP based site used to control access. This way, all security management is done from a single place, and everything is nicely integrated.</p>
<p><span id="more-136"></span></p>
<p>I had already decided to use the KFM ajax file manager, as you can use it stand alone, or have it integrated with TinyMCE or FCKeditor. It has themes, and it has a great ability to add custom calls when starting it up to integrate it into other CMS&#8217;s. Because KFM was all setup to be nicely integrated, I just had to figure out how. While the rest of this post will be KFM specific, the CakePHP integration code should work on any application that has similar integration capabilities as KFM.</p>
<p>At first, I just wanted access to CakePHP&#8217;s sessions, so that I could query the current users session, and then decide if the current user had enough permissions to access KFM or not. While this was the road that I initially wanted to go down, I quickly realized that I would be duplicating much of the code that was already written in my CakePHP site &#8211; mainly all the security calls.</p>
<p>I would have to query for the current users permissions, and then map them out to make sure that the current user had the required permissions to access the KFM application. I already had a component that does this in my CakePHP site. All the controllers and views in the cake application just need to query a single method in this component to check if the current user has the required permissions or not. Wouldn&#8217;t it be great to just re-use this same component &#8211; to just be able to call it from KFM?</p>
<p>Well, it turns out, that with a little bit of work (not too much work &#8211; so don&#8217;t be scared), you can do this!</p>
<p>Let&#8217;s dive in.</p>
<p>KFM has a config.php in it&#8217;s api directory, where you can write custom code which will be executed when KFM starts. Basically, if this script returns true, then KFM launches. So all that is needed is to load CakePHP up in a way that doesn&#8217;t &#8220;take over&#8221; KFM, query the needed CakePHP components/controllers that control authorization in your CakePHP application, and return true if the user has access, or exit and redirect with an error message if the user doesn&#8217;t. So it makes sense that this is where our CakePHP integration will take place.</p>
<p>My KFM\api\config.php file looks like this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cakephp.php'</span><span style="color: #339933;">;</span><br />
<br />
Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'debug'</span><span style="color: #339933;">,</span> 0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Component'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SiteAuth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Controller'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'AppController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Helper'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AppController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$siteAuth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SiteAuthComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SessionHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifySession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authorize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage/files'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'edit'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/bounce/display/AccessDenied/FileManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Ok, there it is, let&#8217;s step through it so that we all understand everything.</p>
<p>This first line is the trickiest:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cakephp.php'</span><span style="color: #339933;">;</span></div></div>
<p>Where is this cakephp.php file, and what&#8217;s in it?</p>
<p>Well, this is a copy of CakePHP&#8217;s index.php that is in the webroot folder. By default this is in the app\webroot folder in the CakePHP distribution, but use the one that is in your webroot folder &#8211; the one that is configured to work for your site. Make a copy of it, and rename it something else. I chose cakephp.php, you can call it anything you like.</p>
<p>At the end of the file, you will see a section that has the following code in it:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'favicon.ico'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$Dispatcher</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Dispatcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$Dispatcher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Configure<span style="color: #339933;">::</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;!-- &quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span>getMicrotime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$TIME_START</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;s --&gt;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>you will want to change it to this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'favicon.ico'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$Dispatcher = new Dispatcher();</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$Dispatcher-&gt;dispatch($url);</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">//if (Configure::read() &amp;gt; 0) {</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//echo &quot;&lt;!-- &quot; . round(getMicrotime() - $TIME_START, 4) . &quot;s --&gt;&quot;;</span><br />
<span style="color: #666666; font-style: italic;">//}</span></div></div>
<p>I left the lines commented so you could easily see the changes that we made, but you could just delete everything from &#8220;else&#8221; onwards &#8211; just make sure that you leave the last &#8216;?&gt;&#8217; ending PHP line at the end of the file.</p>
<p>The first commented section (in the else{} block), is because we don&#8217;t want CakePHP&#8217;s dispatcher, we just want enough of CakePHP to load so that we can use most if it&#8217;s features without cake &#8216;taking over&#8217; and trying to match the URL&#8217;s to controllers and actions.</p>
<p>The second commented section is the  &#8216;if&#8217; block. This is the block of code that prints out the page generation time &#8211; and we don&#8217;t want that present in KFM in any way. We don&#8217;t want CakePHP to echo anything out that will interfere with the HTML that is generated by KFM.</p>
<p>Once these changes are done, simply including this file in KFM&#8217;s config.php will load enough of Cake so that we can &#8220;tap&#8221; into it and use it&#8217;s features.</p>
<p>The next line is:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'debug'</span><span style="color: #339933;">,</span> 0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This is Cake&#8217;s configure array, and we are making sure that there is no Cake debugging on, so that Cake will not &#8220;echo&#8221; anything out to the browser &#8211; we just want KFM to output HTML, not Cake in this case.</p>
<p>The next three lines is where the magic starts happening:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Component'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SiteAuth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Controller'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'AppController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Helper'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>These are straight-up CakePHP import calls. The first App::import (the SiteAuth Component), is the custom component that I was talking about. This is not a CakePHP bundled component, but you may have one that is similar in your CakePHP application.</p>
<p>This component handles all my authorization checks for the entire Cake app, and this is the component that I want to use.</p>
<p>I then load up the AppController, and Session Helper that come with CakePHP.</p>
<p>The next lines simply instatiate instances of the objects that we imported above:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AppController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$siteAuth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SiteAuthComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SessionHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>At this point, I have access to CakePHP&#8217;s sessions, and all the methods/properties that come with the SessionHelper(), along with all of the methods/properties that are available in my AppController(). In addition, I have access to my custom component (SiteAuth). Basically, I have enough of cake loaded to do almost anything I want.</p>
<p>Notice here that I instantiate the SessionHelper() in my siteAuth component&#8217;s Session property. For other people, you can simply instantiate it to something like $session.</p>
<p>You may need to import other objects and instantiate them, the import thing here is that we have access to all of CakePHP. We can load up models, components, controllers, Helpers&#8230;pretty much anything, and start writing PHP in the normal CakePHP way.</p>
<p>Once I have all of the needed CakePHP &#8216;parts&#8217; loaded, I make the calls I need:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifySession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$siteAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authorize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage/files'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'edit'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/bounce/display/AccessDenied/FileManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This again is custom to my application, but basically, you will want to verify that the session is valid, and make authorization calls to whichever component/controller you use to authorize your users. if the test passes, return true, otherwise exit and redirect the user somewhere else (access denied).</p>
<p>I have a simple &#8220;bounce&#8221; controller that basically centralizes all my Flash messages in my CakePHP application. My controller-&gt;redirect call in the end redirects the user to this bounce controller that simply set&#8217;s the appropriate flash message for an &#8220;Access Denied&#8221; error, and uses the argument &#8220;FileManager&#8221; to tell the user that he/she was Denied Access to the File Manager section of the application.</p>
<p>My &#8216;bounce&#8217; controller also takes care of all the needed logic to redirect the user to the last page he/she had access to, or the site&#8217;s root, so if you don&#8217;t already have anything like this setup, you may just want to set a Flash ( $session-&gt;setFlash(); ) message up in here manually and redirect the user ($controller-&gt;redirect(); ) to the site root (or whatever makes sense to you).</p>
<p>Anyways, I hope that this made some sense, and showed you how to load up Cake in a third party app that allows integration, and how to import the needed classes/objects to tap into CakePHP&#8217;s power and features, and re-use your CakePHP controllers and components in an interesting way so that you are not rewriting things from scratch.</p>
<p>Let me know if this helped any of you&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2009/02/using-cakephp-components-in-other-applications/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Ajax Pagination in CakePHP using JQuery</title>
		<link>http://farrworks.com/2009/01/ajax-pagination-in-cakephp-using-jquery/</link>
		<comments>http://farrworks.com/2009/01/ajax-pagination-in-cakephp-using-jquery/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 19:52:24 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=128</guid>
		<description><![CDATA[Today I needed ajax-ified pagination in a cakePHP app, and after looking around a bit, I found an excellent start on this blog: http://lucidchart.blogspot.com/2008/10/jquery-ajax-pagination-for-cakephp-12.html. In this post, I add the ability to show and hide a div to provide user feedback during an Ajax action using Jquery.

Simply put the SetupAJAXPagination() function somewhere, and call $(function(){SetupAJAXPagination(&#8216;CssID&#8217;);}); [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed ajax-ified pagination in a cakePHP app, and after looking around a bit, I found an excellent start on this blog: <a href="http://lucidchart.blogspot.com/2008/10/jquery-ajax-pagination-for-cakephp-12.html">http://lucidchart.blogspot.com/2008/10/jquery-ajax-pagination-for-cakephp-12.html</a>. In this post, I add the ability to show and hide a div to provide user feedback during an Ajax action using Jquery.<br />
<span id="more-128"></span><br />
Simply put the SetupAJAXPagination() function somewhere, and call $(function(){SetupAJAXPagination(&#8216;CssID&#8217;);}); in jquery&#8217;s $(document).ready() function, and you immediately have ajax-ified pagination using cakePHP&#8217;s pagination features.</p>
<p>The only thing else that you may want is to setup some user feedback through some sort of animated GIF (a spinner), or some text telling the user that this section is reloading data from the database, and to be patient.</p>
<p>To do this, all you need is JQuery&#8217;s .ajaxStart and .ajaxStop methods:</p>
<p>just create a div with the image/text that you want to show while the user &#8220;waits&#8221;, something like:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loading&quot;</span>&gt;</span>bla bla bla<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
<p>And then in JQuery&#8217;s $(document).ready() function, add:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxStart</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxStop</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And that is pretty much it. The only thing else that I found today was a nifty little site to generate those animated gifs (spinning/twisting/progress bars) that we all search for. You can choose the colors you want, and can easily sample and download the animated gif that is created for you:</p>
<p><a href="http://www.ajaxload.info/">http://www.ajaxload.info/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2009/01/ajax-pagination-in-cakephp-using-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript Rounded Corners and JQuery</title>
		<link>http://farrworks.com/2008/10/javascript-rounded-corners-jquery-cakephp/</link>
		<comments>http://farrworks.com/2008/10/javascript-rounded-corners-jquery-cakephp/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 04:15:12 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Corners]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=85</guid>
		<description><![CDATA[In one of my projects I needed some nice rounded corners, but I needed to have the flexibility to style them, and change colors easily, and quickly as needed. I usually used Nifty Corners, and have had good success with it, but this time around, I wanted to see if I could do it all [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my projects I needed some nice rounded corners, but I needed to have the flexibility to style them, and change colors easily, and quickly as needed. I usually used <a href="http://www.html.it/articoli/niftycube/index.html">Nifty Corners</a>, and have had good success with it, but this time around, I wanted to see if I could do it all in jquery.<br />
<span id="more-85"></span><br />
First, some background on why I used Nifty in the past. I know that the corners that Nifty produces are not the best quality, but they are passable. Also, the script runs fairly quickly, and can round many corners on a page pretty fast &#8211; fast enough to use on a production site and not have it bog down. Lastly, it has some really cool options that only a few others have, and in some cases nobody has. Stuff like:</p>
<ul>
<li>rounding different types of elements &#8211; not just div&#8217;s, but p&#8217;s, h#&#8217;s, and lists (ordered and unordered) can be specified and rounded.</li>
<li>transparency support</li>
<li>fixed-height option (if you need a fixed height defined in css)</li>
<li>same-height option. this is by far my favorite. you can use this for layouts, or many other things. I once had to make 12 divs the same size &#8211; no matter what data was in them. The layout was a 2 column layout, and so the 12 divs were in two columns of 6 each. If one div needed enough room for 15 lines, all the rest of the divs needed to grow to match the size &#8211; so everything would still look even  &#8211; that is one div should never be smaller or bigger then the rest of them &#8211; all had to be the same size &#8211; no matter what. This can be a litle tricky, but a no-brainer with the same-height option, and you get rounded corners for free too &#8211; bonus!</li>
</ul>
<p>For these reasons, and another being that it&#8217;s soo easy to use, I am a fan of Nifty. Although I knew that I could use it, and that it plays fairly nice with jquery on it&#8217;s own, I wanted to see if I could stay within jquery realm&#8230;</p>
<p>I quickly found some basic corner plugins for jquery to round my corners, but most of them were not pretty at all, no anti-aliasing, and so the corners looked pretty jagged. Not very attractive at all. I know that Nifty Corners isn&#8217;t the best as far as anti-aliasing goes, but these were much worse then the results that one can get with Nifty.</p>
<p>I searched around some more, and pretty much found what I was looking for with the <a href="http://blue-anvil.com/archives/anti-aliased-rounded-corners-with-jquery">&#8220;JQuery Corner&#8221;</a> plugin. The JQuery Corner plugin is more or less a port of the curvy corners script to jquery, so you can use the jquery syntax to locate sections on the page and round them easily. It&#8217;s a simpe as:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rounded'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">corner</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I mean, it can&#8217;t get much easier then this can it! Just use jquery to select the elements you want, and round them. You can also pass the normal curvey corners parameters to control how large the corners should be, which corners should be rounded, etc..</p>
<p>This was fine and all, but I continued my quest to see what other options there were. There was the interesting <a href="http://dev.jquery.com/~paul/plugins/nifty/example.html">Nifty Corners port to jquery</a> which also caught my attention.</p>
<p>At first I thought that this was it&#8230;all the benefits of Nifty right in jquery &#8211; could it be true? Although on it&#8217;s own it did work, I just wasn&#8217;t able to get it working on IE through cakephp for some reason. Other browsers worked fine, but on IE7 &#8211; nothing. No errors, and worst of all, no round corners. I tried different things, but in the end simply gave up. It&#8217;s too bad also, as I really liked this idea.</p>
<p>Well &#8211; all was not lost, as I knew that I could just use Nifty as is, inside jquery&#8217;s $(document).ready() statement. just load up your jquery javascript file, and load Nifty&#8217;s javascript right after. After that, all that is needed is:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Nifty<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rounded'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'big'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Basically, just use Nifty as described in it&#8217;s home page. We are just using jquery&#8217;s document.ready statement to control when Nifty does it&#8217;s job.</p>
<p>Since I now had two options that were interesting, and one was outside of the jquery world &#8211; I thought to myself &#8220;hey, since I am already outside the jquery world &#8211; I might as well try the Cadillac of rounded corners..&#8221;. I have known about, and used <a href="http://www.ruzee.com/blog/shadedborder/">Ruzee&#8217;s corners</a>, but didn&#8217;t like the fact that it&#8217;s heavy. The new one seems a little faster, and although it produces absolutely beautiful corners, it still is heavy and a little slow when trying to round lots of corners on a page. As a simple test, just load up the demo page, and try to scroll around and watch your CPU. Just resize the window, and scroll around and listen to your CPU fan start to kick in.</p>
<p>It also plays nice with jquery &#8211; all that is needed it to simply load up the shadedborder.js file after you load up jquery, and then do something like:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> border <span style="color: #339933;">=</span> RUZEE.<span style="color: #660066;">ShadedBorder</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> corner<span style="color: #339933;">:</span>8<span style="color: #339933;">,</span> shadow<span style="color: #339933;">:</span>16<span style="color: #339933;">,</span> &nbsp;border<span style="color: #339933;">:</span>2 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; border.<span style="color: #660066;">render</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rounded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Again, we are using jquery&#8217;s document.ready statement to control when shadedborder will start doing it&#8217;s magic.</p>
<p>All 3 options are viable in my opinion. Ruzee border is by far the prettiest &#8211; with it&#8217;s drop shadow ability and all, but it&#8217;s also the heaviest by far. If you do use it, use it sparingly. The JQuery Corner plugin is pretty good also, and lighter then Ruzee&#8217;s corners. It also produces nice anti-aliased clean corners, and works in all browsers that I threw at it. And good ol&#8217; Nifty corners with it&#8217;s &#8216;passable&#8217; corners but very usefull features is the lightest and fastest of the bunch. If you have many corners to round in a single page, Nifty is the way to go. You will sacrifice a bit of the look for speed and usability.</p>
<p>As far as script sizes go, it is very surprising that Ruzee and Nifty are tied for 1st place &#8211; with each weighing in at 9KB. Pretty impressive. JQuery Corner is double in size (the minified version) weighing in at 19KB. Although you can use the packed version if you want at 13KB. Still larger then Ruzee or Nifty though.</p>
<p>The one thing that I have left to test is seeing how heavy/fast Ruzee&#8217;s corners are if I get rid of drop shadow (.., shadow:0, &#8230;). At 9KB, it&#8217;s a very impressive library, and produces beautiful results&#8230;.but maybe that will be a discussion for another day.</p>
<p>What is perhaps the most interesting, is that you can use all 3 of them together with ease. So you can use Nifty for the &#8220;I need lots of corners all over the place and so need speed&#8221; things, and then use Ruzee or JQuery Corner when you need larger, prettier corners, but only on an single (or a few) element(s). </p>
<p>For my uses, I think it will be a combination of Nifty and Ruzee, as both are smaller then JQuery Corner&#8217;s, and Ruzee produces &#8220;photoshop quality&#8221; corner effects that are really great.</p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2008/10/javascript-rounded-corners-jquery-cakephp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; There and back again</title>
		<link>http://farrworks.com/2008/09/cakephp-there-and-back-again/</link>
		<comments>http://farrworks.com/2008/09/cakephp-there-and-back-again/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 03:02:44 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=69</guid>
		<description><![CDATA[I have been bouncing between web development frameworks for a little while. So this is a quick tale of my experiences with a couple of them.
First off, all of these frameworks are really great, this is not meant as a &#8220;this framework is better then that framework&#8221; thing. Just my thoughts and finally the decision [...]]]></description>
			<content:encoded><![CDATA[<p>I have been bouncing between web development frameworks for a little while. So this is a quick tale of my experiences with a couple of them.</p>
<p>First off, all of these frameworks are really great, this is not meant as a &#8220;this framework is better then that framework&#8221; thing. Just my thoughts and finally the decision that was made as to which technology/framework I will use for current and future projects.</p>
<p>First off &#8211; the frameworks I have bounced around and used over the last little bit:</p>
<ul>
<li><a href="http://www.cakephp.org" target="_blank">CakePHP</a>
<ul>
<li>PHP web development framework<a href="http://www.djangoproject.org" target="_blank"></a></li>
</ul>
</li>
<li><a href="http://www.djangoproject.org" target="_blank">Django</a>
<ul>
<li>Python web development framework</li>
</ul>
</li>
</ul>
<p><span id="more-69"></span></p>
<p>There have been others, but these two are the two that I have used the most. My idea to go to Python was initially because of language features and performance. Python is a really great language that I enjoy developing in. The use of mod_python and apache with a great framework like Django is very appealing. Django is one of the hottest things right now in the python world, and so I jumped on that train with both of my feet.</p>
<p>After tweaking Apache and mod_python, I had an example app serving a consistent 500 requests per second &#8211; not too bad at all. I was pretty impressed, and I knew that that was just the start. I still hadn&#8217;t started messing with memcache configurations and load balancing architectures, which I knew that a couple of these projects would need, so a base of 500 rps was very satisfying.</p>
<p>The only issue I had on the performance side was the CPU. mod_python did use more CPU on average to serve the same example app written in CakePHP. That being said, mod_python and Django did serve the app faster then CakePHP, at least twice as fast. So using more CPU could be a satisfactory trade-off on that end.</p>
<p>So I left the PHP/CakePHP camp for a bit, and fooled around in the Django camp. Built a couple of sites, and everything seemed like it was going really well. So well infact, that I wondered why I didn&#8217;t do this sooner. Time went on, and the site started getting more and more complex, and soon I was starting to do a lot of &#8220;grunt work&#8221; so to speak. </p>
<p>More time went on, and I was finding issue after issue that I was having to write from scratch. More and more time was spent searching around to see if anyone else had done this or that, and try to &#8220;snap-in&#8221; code from all over the place. The end result was that I was spending more time searching, and trying, and searching again, and trying again for things online to make sure that I wasn&#8217;t recreating the wheel, then actual coding of business/application logic.</p>
<p>One such example was data-sets/data-grids. It is a basic, common feature to display a table that is filled with data retrieved from a database. It is also very basic these days to have it sortable, and paginated. Datasets/grids make this job very easy on the developer. I fell in love with the way dotNet 2.0 does this &#8211; it&#8217;s approach is wonderful. CakePHP also has very nice ways to deal with this, and is extremely easy to use. After searching online 15 or so minutes, I found that there were a couple of &#8220;Django&#8221; approaches from the community, and an hour+ later, did have some working datasets, but again, I felt like I was simply doing too much leg work. </p>
<p>That is an hour lost. Never again will I be able to get that hour back. You pile on that hour, with the previous hours of doing similar things, and  you end up being a little frustrated and wondering as to why you are behind. At first it&#8217;s a learning curve, and you are expected to be slower. But after a while, the expectation is that at least  you should be as fast as before. Hopefully faster.</p>
<p>PHP can be a very sloppy language. There is less consistency in the language, and there is a fairly large legacy of &#8220;the old ways&#8221; that PHP is still dealing with. PHP 5 was a good step in the right direction, and added some very much needed things to the language, but it has been slow to adopt for some reason.</p>
<p>But. But. But&#8230;..there is always a &#8220;but&#8221;.</p>
<p>PHP can be very nice to program in also. It is supported all over the place, has a huge community, and runs almost anywhere. Before jumping on the Django/Python train, all my web development was done in PHP for years and years. It is one of the web platforms that I now best, and am comfortable in. For me, the decision to go back to PHP, and CakePHP in specific, was a choice that I thought about, and weighed. CakePHP has really great features, is documented fairly well, and wastes less of my time.</p>
<p>I will say that again: CakePHP wastes less of my time.</p>
<p>It really was a no-brainer to go back&#8230;</p>
<p>So &#8211; I say hello again to cakePHP, and bye-bye for now to python&#8230;maybe one day I will go back, as I do really like the language and it&#8217;s offerings, who knows. But for now, I am back to making cake&#8217;s with PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2008/09/cakephp-there-and-back-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
