<?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>Jotlab &#187; plugin</title>
	<atom:link href="http://www.jotlab.com/tag/plugin/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jotlab.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 22 Mar 2013 01:15:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Form Keeper: Field Name Obfuscation for CakePHP Forms</title>
		<link>http://www.jotlab.com/2011/form-keeper-field-name-obfuscation-for-cakephp-forms</link>
		<comments>http://www.jotlab.com/2011/form-keeper-field-name-obfuscation-for-cakephp-forms#comments</comments>
		<pubDate>Sun, 27 Feb 2011 10:33:57 +0000</pubDate>
		<dc:creator>voidet</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formhelper]]></category>
		<category><![CDATA[formkeeper]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[keeper]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.jotlab.com/?p=4650</guid>
		<description><![CDATA[I don&#8217;t like giving my end users information about the inner workings of the system they&#8217;re using. Even though the system itself might be secure in terms of what data it can take in, how it treats the data and what it returns, I still... <span><a href="http://www.jotlab.com/2011/form-keeper-field-name-obfuscation-for-cakephp-forms" title="Form Keeper: Field Name Obfuscation for CakePHP Forms" rel="bookmark">[+]</a></span>]]></description>
				<content:encoded><![CDATA[<p>I don&#8217;t like giving my end users information about the inner workings of the system they&#8217;re using. Even though the system itself might be secure in terms of what data it can take in, how it treats the data and what it returns, I still don&#8217;t like the fact extra, inner system specs are publicly visible to the end user.</p>
<h2>What Is Form Keeper?</h2>
<p>This is where Form Keeper steps in. Form Keeper is a CakePHP 1.3 plugin that takes over from where CakePHP&#8217;s awesome Form Helper left off. Usually your forms would be constructed in a way like:</p>
<pre class="brush: php; title: ; notranslate">&lt;input name=&quot;data[ModelName][field_name]&quot; id=&quot;ModelNameFieldName&quot; value=&quot;&quot; type=&quot;hidden&quot; /&gt;</pre>
<p>This is all well and good. PHP will take those posted results, turn the data into a multidimensional array, pass it onto CakePHP and CakePHP will handle the rest, like a boss. The only problem with this is, it leaves a bad feeling in my stomach, in that, the end user knows your models, your field names in the database. Now there may be no immediate security threat with that, but less information provided, means less information for the end user to get construct blueprints of your database. So with FormKeeper you get:</p>
<p>
<pre class="brush: xml; title: ; notranslate">&lt;input name=&quot;6a03949c66c7cc5c7bce550c21308659c1d848a7&quot; type=&quot;text&quot; maxlength=&quot;40&quot; id=&quot;6a03949c66c7cc5c7bce550c21308659c1d848a7&quot;&gt;</pre>
</p>
<h2>What FormKeeper Does</h2>
<p>Form Keeper takes your forms, with all the power of CakePHP&#8217;s FormHelper, and adds a layer of one way encryption to your field names and field id&#8217;s. These values are firstly SHA1&#8242;d, cached locally into a hash table of your choice (using CakePHP&#8217;s cache engine, also check out my CakePHP SuperStack plugin for some cache redundancy action), then outputted to the view. When the form is then submitted, FormKeeper checks the value is in the hash table, reconstructs the data multidimensional array, and inserts the values.</p>
<p>Now if you are thinking &#8220;this is all good, but CakePHP&#8217;s security component is a mean bastard when it comes to forms and blackhole-ing&#8221;, well that part is covered. The tokenizing works just fine with this plugin, so you can use the security component alongside the FormKeeper for obfuscation and form tampering fun.</p>
<h2>Setting FormKeeper Up</h2>
<p>This is all well and good, but how do I set FormKeeper up? Quite easily, FormKeeper is a CakePHP plugin, so all you need to do is clone the Github repository to your plugins directory and then include both the plugin&#8217;s helper and component elements to either your AppController (if you want to use it site wide) or to the controller of your choice.</p>
<pre class="brush: bash; title: ; notranslate">git clone https://github.com/voidet/form_keeper app/plugins/form_keeper</pre>
<p>Or if you use submodules (like you should):</p>
<pre class="brush: bash; title: ; notranslate">git submodule add https://github.com/voidet/form_keeper app/plugins/form_keeper
git submodule init
git submodule update</pre>
<p>From there all that is left is adding it to your controller(s):</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

class UsersController extends AppController {

	public $components = array('FormKeeper.FormKeeper');
	public $helpers = array('FormKeeper.FormKeeper');</pre>
<p>Now user views have access to the FormKeeper power! But how do views use it? Easy, instead of <strong>$this->Form</strong>, you will now use <strong>$this->FormKeeper</strong>, for everything!</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

echo $this-&gt;FormKeeper-&gt;create();
echo $this-&gt;FormKeeper-&gt;input('username');
echo $this-&gt;FormKeeper-&gt;input('password');
echo $this-&gt;FormKeeper-&gt;input('remember_me', array('type' =&gt; 'checkbox'));
echo $this-&gt;FormKeeper-&gt;end('Login');</pre>
<h2>Configuration</h2>
<p>There are two parameters (so far) that you can change for the plugin. It&#8217;s as simple as adding in a configuration file into your app/config folder, named form_keeper.php, app/config/form_keeper.php. The two parameters that can be changed is the salt string to encrypt with (if not provided the Security.salt value in core.php will be used) and the cache config that you want to use (by default it will be the default core cache config, which is usually file). So create app/config/form_keeper.php and add in:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

$config['FormKeeper'] = array(
	'salt' =&gt; 'ixNE257AeJI2mbVicRwjEFM169seG59lzmxP8N4Z',
	'cacheKey' =&gt; 'default',
);</pre>
<p>Also please note that the Id&#8217;s of the input field are also hashed. To avoid this, you can simply provide an id in your input options, as you would to override cake&#8217;s default ID. This is primarily used for object selection in the DOM with jQuery etc.</p>
<h2>Security Component</h2>
<p>CakePHP has an excellent form tampering protection method that comes standard with the Security Component. It basically takes all the form fields in the view/layout between create and end, serializes their names and then hashes this into a token. The token is stored in a hidden field within the form, and once posted back is then checked against the posted data keys. If there is any variance in the rehashed field names that have been posted and in the token field then the user&#8217;s request will be blackHoled, effectively white screen of death (which can be easily overridden for your security pleasure).</p>
<p>FormKeeper maintains this level of security and functionality of CakePHP&#8217;s security component. The way FormKeeper achieves this is simply down to order of execution. FormKeeper taps into the power of the Form Helper by overriding how it creates field names. So basically Security Component generates it&#8217;s tokens (found in Form::secure()) against FormKeepers new field names. Coming back is also a matter of execution. FormKeeper remaps/restitches the hashed/protected field names back into the proper data[Model][fieldname] structure, because Security Component get&#8217;s its eager hands on the data ready to crush with the blackHole method. So in effect FormKeeper gets in and out before Security component knows any different.</p>
<h2>Thats It!</h2>
<p>This is an early release of the plugin, and is not tested in production just yet. Expect many updates to come in the near future, and hopefully some test cases to be written. Also if you&#8217;re using the security component, then please include it after the FormKeeper component at this point in time, as that is what has been *thoroughly* tested with. Thank you in advance for any comments and feedback left! If you&#8217;re having issues with the plugin, I usually respond pretty fast with updates or advice. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jotlab.com/2011/form-keeper-field-name-obfuscation-for-cakephp-forms/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sign Me Up A CakePHP User Registration Plugin</title>
		<link>http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin</link>
		<comments>http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin#comments</comments>
		<pubDate>Sat, 29 Jan 2011 02:37:47 +0000</pubDate>
		<dc:creator>voidet</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[activation]]></category>
		<category><![CDATA[me]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[registration]]></category>
		<category><![CDATA[sign]]></category>
		<category><![CDATA[signmeup]]></category>
		<category><![CDATA[up]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.jotlab.com/?p=4637</guid>
		<description><![CDATA[Finding myself generating registration forms now and then for various sites, I found the whole process of replicating the same functionality over to different projects. It didn&#8217;t take long for me to realise that a plugin was the best answer to ease of replication and... <span><a href="http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin" title="Sign Me Up A CakePHP User Registration Plugin" rel="bookmark">[+]</a></span>]]></description>
				<content:encoded><![CDATA[<p>Finding myself generating registration forms now and then for various sites, I found the whole process of replicating the same functionality over to different projects. It didn&#8217;t take long for me to realise that a plugin was the best answer to ease of replication and code reuse, so the Sign Me Up CakePHP plugin was released.</p>
<h2>CakePHP 2.0</h2>
<p>SignMeUp has now been updated to work with CakePHP 2.0. There will be a few more updates in the next few days after I get better access to the internet. Any issues either comment here or open up an issue ticket on Github. To check out the 2.0 updates simply clone down SignMeUp and then do git checkout 2.0.</p>
<p>https://github.com/voidet/sign_me_up/tree/2.0</p>
<h2>Introduction</h2>
<p>Sign Me Up is a CakePHP plugin that allows you to easily integrate a user sign up form. It comes with:</p>
<ul>
<li>User registration form with basic fields Username, email, password and password confirmation.</li>
<li>Default field validation which can be easily overwritten in your models.</li>
<li>Welcome email sending upon successful registration.</li>
<li>User activation code generation and activation via a link/post.</li>
<li>Integrates with Auth settings for redirects and email/view templates easily overwritten.</li>
</ul>
<p><strong>Where to get it:</strong> <a href="https://github.com/voidet/sign_me_up">https://github.com/voidet/sign_me_up</a><br />
<strong> Clone with git:</strong> git clone https://github.com/voidet/sign_me_up.git</p>
<h2>Using Sign Me Up</h2>
<p>Firstly you will need to clone the plugin into your plugins directory:</p>
<pre class="brush: bash; title: ; notranslate">cd /the/path/to/my/cakeapp/app/plugins/
git clone https://github.com/voidet/sign_me_up.git</pre>
<p>Now that we have the plugin available to us, it is time to attach it to your controller/models. To do so you will need to add the Sign Me Up component to the controller that handles your user functions, such as login etc. Add in the component code for example:</p>
<pre class="brush: php; title: ; notranslate">class UsersController extends AppController {
public $components = array('SignMeUp.SignMeUp');</pre>
<p>That&#8217;s one part of the story, however it is probably best to add in the behaviours to your user/member model also:</p>
<pre class="brush: php; title: ; notranslate">class User extends AppModel {
public $actsAs = array('SignMeUp.SignMeUp');</pre>
<p>Next up in your controller you will need to create the actions and link them up to the Sign Me Up plugin:</p>
<pre class="brush: php; title: ; notranslate">public function register() {
$this-&gt;SignMeUp-&gt;register();
};

public function activate() {
$this-&gt;SignMeUp-&gt;activate();
}

public function forgotten_password() {
$this-&gt;SignMeUp-&gt;forgottenPassword();
}</pre>
<p>It&#8217;s pretty easy from there. You can make custom routes to these actions to keep your urls SEO friendly or whatever you like.</p>
<h2>Configuration</h2>
<p>Sign me up uses a basic config file which should be stored in app/config/sign_me_up.php If you don&#8217;t have this file then the Sign Me Up plugin will exit with a message saying it could not find the config file. SignMeUp configuration allows you to overwrite all default CakePHP email parameters by simply specifying the elements in the SignMeUp configuration array i.e change email sending to HTML format via setting the sendAs to HTML or change the email layout with &#8216;layout&#8217; =&gt; &#8216;myLayout&#8217;. The only thing that you would need to diverge from the Email Component settings with is the welcome and activate templates. You can set them with welcome_template and activation_template elements:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$config['SignMeUp'] = array(
	'from' =&gt; 'MyDomain.com &lt;admin@exampledomain.com&gt;',
	'layout' =&gt; 'default',
	'welcome_subject' =&gt; 'Welcome to MyDomain.com %username%!',
	'activation_subject' =&gt; 'Activate Your MyDomain.com Account %username%!',
	'sendAs' =&gt; 'html',
	'activation_template' =&gt; 'activate',
	'welcome_template' =&gt; 'welcome',
	'password_reset_template' =&gt; 'forgotten_password',
	'password_reset_subject' =&gt; 'Password reset from MyDomain.com',
	'new_password_template' =&gt; 'new_password',
	'new_password_subject' =&gt; 'Your new password from MyDomain.com',
	'xMailer' =&gt; 'MyDomain.com Email-bot',
);</pre>
<p>Also note you can include fields in the subject line from your user model. Simply specify the field name you want placed in the subject line with %field_name%. That is that!</p>
<h2>The Views</h2>
<p>The plugin allows the end user to easily overwrite the view files for emails and the front end forms etc. Firstly to create your registration page make a new view in your views/users/register.ctp You can then add in all your design elements or simply include the default Sign Me Up registration element via:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;element('register', array('plugin' =&gt; 'SignMeUp')); ?&gt;</pre>
<p>The same goes with the activation element, which you can include in views/users/activate.ctp</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;element('activate', array('plugin' =&gt; 'SignMeUp')); ?&gt;</pre>
<p>Also for the forgot your password page, views/users/forgotten_password.ctp</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;element('forgotten_password', array('plugin' =&gt; 'SignMeUp')); ?&gt;</pre>
<h2>Email Templates</h2>
<p>You will need to create the CakePHP layouts and views to use. I have only used text based emails, quite simple. So to do so create a new layout in app/views/layouts/emails/text/default.ctp with</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $content_for_layout; ?&gt;</pre>
<p>And now for the welcome email view, which comes with the activation code:</p>
<p>Registration (app/views/elements/email/text/welcome.ctp):</p>
<pre class="brush: php; title: ; notranslate">Welcome &lt;?php echo $user['username']; ?&gt;,

In order to get started please click on the following link to activate your account:

&lt;?php echo Router::url(array('action' =&gt; 'activate', 'activation_code' =&gt; $user['activation_code']), true).&quot;n&quot;; ?&gt;
We look forward to seeing you!
Regards,
MyDomain.com Staff</pre>
<p>Also your forgotten password email template can look something like, app/views/elements/email/text/forgotten_password.ctp</p>
<pre class="brush: php; title: ; notranslate">Hi &lt;?php echo $user['username']; ?&gt;,

Someone (hopefully you) has requested a password reset on your account. In order to reset your password please click on the link below:

&lt;?php echo $this-&gt;Html-&gt;link('Reset your password', Router::url(array('action' =&gt; 'forgotten_password', 'password_reset' =&gt; $user['password_reset']), true)); ?&gt;

Regards,
MyDomain.com Staff</pre>
<h2>We Dont Need No, Activation</h2>
<p>So you want a basic sign up system, but want to knock out the user activation hassle? Well to do so simply ensure that you have setup the SignMeUp plugin to have no activation field set. To do that simply set your activation_field to false:</p>
<pre class="brush: php; title: ; notranslate">	public $components = array('SignMeUp.SignMeUp' =&gt; array(
'activation_field' =&gt; false,
'useractive_field' =&gt; false,
));</pre>
<p>You can also see that useractive_field is set to false, this is for fields that signify if the user is active or not, and saves a boolean value. With the activation_field set to false this will, instead of sending out an activation email, send out a welcome email, of which can be defined in the SignMeUp configuration file as above.</p>
<p>Please note that if you want to use a welcome email, the template of the email should be specified in your SignMeUp config file, and then created. All the user information will still be available.</p>
<h2>I Need Help</h2>
<p>That is a quick summary of the basic functions of the Sign Me Up plugin. The plugin will be developed further as either users request features or I need them built in for my own projects. Just to eliminate any confusion, a look at some routes you might want to use:</p>
<pre class="brush: php; title: ; notranslate">Router::connect('/register', array('controller' =&gt; 'users', 'action' =&gt; 'register'));
Router::connect('/activate', array('controller' =&gt; 'users', 'action' =&gt; 'activate'));
Router::connect('/activate/:activation_code', array('controller' =&gt; 'users', 'action' =&gt; 'activate'), array('pass' =&gt; 'activation_code'));
Router::connect('/forgotten_password/:password_reset', array('controller' =&gt; 'users', 'action' =&gt; 'forgotten_password'), array('pass' =&gt; 'password_reset'));
Router::connect('/login', array('controller' =&gt; 'users', 'action' =&gt; 'login'));
Router::connect('/logout', array('controller' =&gt; 'users', 'action' =&gt; 'logout'));</pre>
<p>If you need any assistance or find bugs, please leave a comment and I can help you out patch some bugs <img src='http://www.jotlab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>I Put What Where?</h2>
<p>There has been some confusion as to what fields are required or optional in your authentication table (users, members etc table). Also people are finding that their emails are being sent out, or max execution time is being hit. This section will help describe what to do with your database, where to put the email files and how to send out emails.</p>
<h3>My DB Table</h3>
<pre class="brush: sql; title: ; notranslate">CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(40) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `password` varchar(40) DEFAULT NULL,
  `activation_code` varchar(40) DEFAULT NULL,
  `active` tinyint(1) DEFAULT NULL,
  `password_reset` varchar(40) DEFAULT NULL,
  `created` timestamp NULL DEFAULT NULL,
  `modified` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
); </pre>
<p>This uses the default values found in SignMeUp. You can override these as mentioned above in your sign_me_up.php config file which should be stored in app/config/sign_me_up.php</p>
<h3>My Email Files</h3>
<p>This section really depends what email type you are sending out, html, text-only, or both. Either way. Lets say we are sending out text only emails, you will need to first make the layout file in <strong>app/views/layouts/email/text/default.ctp</strong> and just put in <strong><?php echo $content_for_layout; ?></strong></p>
<p>Next up you need to setup your email templates. The email templates are basically your view for each email that you send out, be it the welcome or activation emails for example. So in order to send out a welcome email you would make your file in <strong>app/views/elements/email/text/welcome.ctp</strong> This template is as defined in your sign_me_up.php configuration file. You can use the example welcome text as seen above.</p>
<p>Basically you need to include your email layouts and templates in your application, not inside the sign_me_up plugin.</p>
<h3>Max Execution time being hit</h3>
<p>I have seen one person hit this issue and it comes down to email sending. If you are using SMTP for your email sending type then make sure your network that you&#8217;re on allows connection to whatever address you&#8217;re trying to send out to. A max execution time is being hit because the application cannot establish a connection to the smtp server and is left hanging.</p>
<h2>Updates</h2>
<p>To make things easy, I will keep any updates on the GitHub page and updates written below here as a small change log:</p>
<p><strong>0.7 </strong>Added in forgotten password functionality<strong><br />
0.6</strong> Pushed updates that now allow user activation to be optional. Activations will only be attempted if the default settings of activation_field is not set to false.<br />
<strong>0.5.5</strong> Bug Fixes thanks to the comments received<br />
<strong>0.5</strong> Initial Release</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin/feed</wfw:commentRss>
		<slash:comments>169</slash:comments>
		</item>
		<item>
		<title>My CakePHP Category Tree Helper</title>
		<link>http://www.jotlab.com/2009/my-cakephp-category-tree-helper</link>
		<comments>http://www.jotlab.com/2009/my-cakephp-category-tree-helper#comments</comments>
		<pubDate>Wed, 08 Apr 2009 07:27:03 +0000</pubDate>
		<dc:creator>voidet</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[cake]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://www.jotlab.com/?p=3788</guid>
		<description><![CDATA[Hey everyone. Not so much a tutorial here, but more so a snippet of code to help some of you out. My problem was with the CakePHP tree component. The way that the tree organised data in CakePHP works is through establishing a neighbour like... <span><a href="http://www.jotlab.com/2009/my-cakephp-category-tree-helper" title="My CakePHP Category Tree Helper" rel="bookmark">[+]</a></span>]]></description>
				<content:encoded><![CDATA[<p>Hey everyone. Not so much a tutorial here, but more so a snippet of code to help some of you out. My problem was with the CakePHP tree component. The way that the tree organised data in CakePHP works is through establishing a neighbour like system, where the elements are located through analysing not only the parent and children relationships but through where each element is located according to its neighbour. The problem i found with this when it comes to categories is that CakePHP does not seem to have a way to ignore this left and right neighbour checks, and in turn order the data.</p>
<p>So after asking around a bit i decided to write my own method of ordering my tree data in the database, which was a Category list to be used in a select box. My helper came out to be:</p>
<p>/app/views/helpers/tree.php</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
	
	class TreeHelper extends AppHelper {
		
		function indentTree($array, $counter=0){
			$ret = '';
			$array2 = array();
			$pre = '';
			for($i = 1;$i &lt; $counter; $i++){
				$pre .= '--';
			}
			
			foreach($array as $key =&gt; $value){
				if($key == 'children'){
					if(isset($value['Category']) || (isset($value['children']) &amp;&amp; sizeof($value['children']) &gt; 0)){
						$indented[] = $this-&gt;indentTree($value, ++$counter);
					} else {
						if(sizeof($value) &gt; 0) {
							$indented[] = $this-&gt;indentTree($value, $counter);
						}
					}
				}	elseif($key == 'Category'){
					$indented[$value['id']] = ' '.$pre.' '.$value['name'];
				}	elseif(isset($value['Category']['name'])){
					$indented[] = $this-&gt;indentTree($value, $counter);	
				}
			}
			return $this-&gt;flatten_array($indented, 2);
		}
		
		function flatten_array($array, $preserve_keys = 0, &amp;$out = array()) {
			foreach($array as $key =&gt; $child){
				if(is_array($child)){
					$out = $this-&gt;flatten_array($child, $preserve_keys, $out);
				} elseif($preserve_keys + is_string($key) &gt; 1){
					$out[$key] = $child;
				} else {
					$out[] = $child;
				}
			}
			return $out;
		}
		
	}	
	
?&gt;</pre>
<p>To use this simply include the helper in your controller via:</p>
<pre class="brush: php; title: ; notranslate">var $helpers = array('Html', 'Form', 'Text', 'Javascript', 'Tree');</pre>
<p>And then within your action you must select the data in a threaded form, the same as GenerateTreeList would do, however pre-ordered:</p>
<pre class="brush: php; title: ; notranslate">$categories = $this-&gt;Category-&gt;find('threaded', array('order' =&gt; array('Category.name' =&gt; 'ASC')));
$this-&gt;set('categoriesList', $categories);</pre>
<p>Next up you use the helper in your view via:</p>
<pre class="brush: php; title: ; notranslate">echo $form-&gt;input('parent_id', array('type'=&gt;'select', 'options'=&gt;$tree-&gt;indentTree($categoriesList), 'empty'=&gt;'--------', 'div'=&gt;'row'));</pre>
<p>And thats it!<br />
For me this will return an ordered flattened array of my categories to be used within the select box!<br />
I know this explanation is a bit low but it should be enough to get you started! If you have any questions please comment and i will see what i can do to help you out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jotlab.com/2009/my-cakephp-category-tree-helper/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
