<?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>Flipflops.org &#187; CakePHP</title>
	<atom:link href="http://www.flipflops.org/category/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flipflops.org</link>
	<description>Flipflops.org is about web development and fairly conceptual art</description>
	<lastBuildDate>Tue, 31 Jan 2012 23:26:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Lithium, Doctrine &amp; doing it yourself</title>
		<link>http://www.flipflops.org/2009/10/30/lithium-doctrine-doing-it-yourself/</link>
		<comments>http://www.flipflops.org/2009/10/30/lithium-doctrine-doing-it-yourself/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 22:12:38 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/10/30/lithium-doctrine-doing-it-yourself/</guid>
		<description><![CDATA[If you use CakePHP you&#8217;ll probably be aware (or you&#8217;re dead or on holiday or something&#8230;) that Gwoo and Nate have left the project and gone elsewhere. Sort of. Well actually they have forked Cake3 into Lithium &#8211; souped up CakePHP for PHP 5.3 Unfortunately I&#8217;m not going to be using it in the immediate [...]]]></description>
			<content:encoded><![CDATA[<p>If you use CakePHP you&#8217;ll probably be aware (or you&#8217;re dead or on holiday or something&#8230;) that Gwoo and Nate have left the project and gone elsewhere. Sort of. Well actually they have forked Cake3 into <a href="http://li3.rad-dev.org/">Lithium</a> &#8211; souped up CakePHP for PHP 5.3</p>
<p>Unfortunately I&#8217;m not going to be using it in the immediate future due to the 5.3 limitation, but I had a good look through the <a href="http://rad-dev.org/lithium_examples">blog example</a> and it looks like it would be a pleasure to work with.</p>
<p>Looking round the Lithium site I also came across <a href="http://www.doctrine-project.org/">Doctrine</a> &#8211; an object relational mapper (ORM) system. I spent an evening reading the documentation and decided it was perfect for a project I&#8217;m working on at work, unfortunately the next day I discovered we aren&#8217;t up to the required PHP version yet (almost, but not quite) so on the back burner for now.</p>
<p>I&#8217;m building a small application (about 8 tables) to be integrated into an existing CMS system. The structure of the CMS is essentially front controller based with a great template engine and well developed plugin / module system. The new module I&#8217;ve had to develop just didn&#8217;t fit well into the existing code structure and so I have ended up writing a Model / Controller system within my module that utilizes the things like the DB library, routing, security, templating etc. of the parent application.</p>
<p>The setup is pretty straight forward &#8211; a base model and base controller extended by respective models and controllers for each table. The child controllers and models are mostly pretty thin &#8211; mostly just setting class specific instance variables and the calling methods in the base classes with parent:: There isn&#8217;t any fancy ORM or anything like that in the models, just good old fashioned SQL, one query or closely related group of queries per method.</p>
<p>It took me about 1 1/2 days to write the framework and about another half day to write the templates (I&#8217;ve still got a load of reporting etc. to write) but now I&#8217;ve got the views for all the CRUD operations I will need and a lot of reusable code. Thinking about it, I would probably have done about a quarter of the work, in a far less maintainable way if I hadn&#8217;t taken this route. Goes to show that as long as your goals are well defined &#8211; this kind of approach far from being overkill has saved a huge amount of time and produced very understandable code &#8211; and you don&#8217;t need an entire framework to do it (with the added advantage that if you write stuff yourself, you hopefully have a better grasp of what is going on).</p>
<p>(I&#8217;ve still written a fair amount of Cake code this week <img src='http://www.flipflops.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/10/30/lithium-doctrine-doing-it-yourself/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP Menu Helper for Tree data</title>
		<link>http://www.flipflops.org/2009/09/29/cakephp-menu-helper-for-tree-data/</link>
		<comments>http://www.flipflops.org/2009/09/29/cakephp-menu-helper-for-tree-data/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 19:11:03 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/09/29/cakephp-menu-helper-for-tree-data/</guid>
		<description><![CDATA[This is the MenuHelper I use in my CMS system. It is designed to work with data from the Tree behaviour or from any $model->find(&#8216;threaded&#8217;) call. I use it to generate multi level CSS menus (that you see at the top of most websites), contextual menus (that you see in sidebars, showing the current page [...]]]></description>
			<content:encoded><![CDATA[<p>This is the MenuHelper I use in my CMS system. It is designed to work with data from the Tree behaviour or from any $model->find(&#8216;threaded&#8217;) call. I use it to generate multi level CSS menus (that you see at the top of most websites), contextual menus (that you see in sidebars, showing the current page and its &#8216;branch&#8217;) and sitemaps &#8211; which let&#8217;s face it are basically often just the same as a top level menu but without the fancy stuff to make them pop out when you hover over them.</p>
<h2>Prerequisites, history, overview</h2>
<p>There are a couple of prerequisites here which may mean that this isn&#8217;t applicable for a lot of people. The helper is designed to deal with &#8216;page&#8217; structures organised in simple /parent/child/grand-child format e.g.</p>
<p>/home<br />
/about<br />
/about/company-history<br />
/about/company-history/gallery<br />
/about/ethos<br />
/about/vacancies<br />
/news<br />
/news/2009/jan<br />
/news/2009/feb<br />
/news/2009/mar<br />
/contact<br />
(etc.)</p>
<p>In my system I have a model &#8216;Article&#8217; with Tree behaviour attached. So in the example above &#8216;ethos&#8217; is a child of &#8216;about&#8217;. Some of these pages have real content, but others just act as place holders for other controllers / models &#8211; &#8216;news&#8217; is a placeholder for the &#8216;News&#8217; model. But all of them (even the placeholders) have other data attached like content for sidebars or meta information.</p>
<p>The helper will add a &#8216;selected-item&#8217; class to the LI corresponding to the current page, and if it has any parents it will add a &#8216;selected&#8217; class to each of those parent LIs too.</p>
<p><strong>I create a full slug for each &#8216;Article&#8217; on $model->save()</strong></p>
<p>The helper operates in 2 modes &#8216;tree&#8217; (which is default) and &#8216;context&#8217;<br />
&#8216;tree&#8217; will produce a whole list of nested ULs &#8211; can be used to generate top level navigation (works well with things like suckerfish)<br />
&#8216;context&#8217; will only produce nested ULs for the current branch</p>
<p>Using the example above if you were on the /about/ethos page and you wanted the navigation fragment in the sidebar you would use &#8216;context&#8217;<br />
/about<br />
/about/company-history<br />
/about/company-history/gallery<br />
/about/ethos<br />
/about/vacancies</p>
<h2>Database Fields</h2>
<p>These are the default field names, they can be simply overridden to match your database schema.</p>
<h3>Required Fields</h3>
<ul>
<li>name </li>
<li>slug_url</li>
</ul>
<h3>Optional Fields</h3>
<ul>
<li>title_for_navigation</li>
<li>redirect_url</li>
<li>redirect_target</li>
</ul>
<h2>Example &#8216;threaded&#8217; data</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>Article<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                <span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Find out about us
                    <span style="color: #009900;">&#91;</span>slug_url<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">/</span>about<span style="color: #339933;">-</span>us
                    <span style="color: #009900;">&#91;</span>title_for_navigation<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> About Us
                    <span style="color: #009900;">&#91;</span>redirect_url<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                    <span style="color: #009900;">&#91;</span>redirect_target<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                    <span style="color: #009900;">&#91;</span>lft<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span>
                    <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">105</span>
                    <span style="color: #009900;">&#91;</span>rght<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">24</span>
                    <span style="color: #009900;">&#91;</span>parent_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                <span style="color: #009900;">&#41;</span>
&nbsp;
            <span style="color: #009900;">&#91;</span>children<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                <span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                        <span style="color: #009900;">&#40;</span>
                            <span style="color: #009900;">&#91;</span>Article<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                                <span style="color: #009900;">&#40;</span>
                                    <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Philosophy
                                    <span style="color: #009900;">&#91;</span>slug_url<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">/</span>about<span style="color: #339933;">-</span>us<span style="color: #339933;">/</span>philosophy
                                    <span style="color: #009900;">&#91;</span>title_for_navigation<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                                    <span style="color: #009900;">&#91;</span>redirect_url<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                                    <span style="color: #009900;">&#91;</span>redirect_target<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
                                    <span style="color: #009900;">&#91;</span>lft<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">16</span>
                                    <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">111</span>
                                    <span style="color: #009900;">&#91;</span>rght<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">21</span>
                                    <span style="color: #009900;">&#91;</span>parent_id<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">105</span>
                                <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<h2>Usage</h2>
<p>Include the helper in your controller as usual.</p>
<p>In a view / element to generate complete menu</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$menu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu_data</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'selected'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">here</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In a view / element to generate a context menu from the same data, set the class of the parent UL</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$menu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu_data</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'selected'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">here</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'context'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'menuClass'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'context-menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In a view / element to generate a sitemap from different data, let the helper know to use the &#8216;Sitemap&#8217; model rather than the default &#8216;Article&#8217; model and set the parent UL class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$sitemap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MenuHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$sitemap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modelName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sitemap'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'menuClass'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sitemap'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>The Helper Code</h2>
<p><strong><a href="/scripts/menu.php.txt">Download the Helper</a></strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Menu Helper
 * 
 * @author John Elliott (http://www.flipflops.org)
 * @package app
 * @subpackage app.views.helpers
 * @version 1.0
 * @lastmodified 2009-09-29
 * 
 * This helper is designed to work with the data arrays returned by the Tree behaviour or $model-&gt;find('threaded');
 * More specifically it is designed to generate menus composed of nested ULs for use in CMS systems where all the URLs are pretty:
 * 	- naviagtion menus (usually at the top of the page)
 * 	- context menus (usually found at the side) and showing the links in the current branch
 * 	- sitemaps
 * 
 * Overview (A bit of history)
 * 
 * The helper is designed to deal with navigation / page structures organised in simple /parent/child/grand-child like structures
 * for instance:
 * 
 * /home
 * /about
 * /about/company-history
 * /about/company-history/gallery
 * /about/ethos
 * /about/vacancies
 * /news
 * /news/2009/jan
 * /news/2009/feb
 * /news/2009/mar
 * /contact
 * (etc.)
 * 
 * -------------------
 * URLs are generated in the model or controller not in the view / helper
 * -------------------
 * In the system from which this is taken, I create a full slug for each page on $model-&gt;save();
 * Some of the pages are actual pages of text and others are palceholders for content in other models
 * but they allow you do things like control the content of left / right columns, set default meta tags etc.
 * The purpose being to create really easy site structures with nice urls, the 
 * In the example above /home, /about etc. are all from a single model 'Article' which is my master model 
 * /news however is a placeholder for the 'News' model and /contact for the 'Contact' model
 * 
 *
 * 
 * Required Fields
 * ------------------
 * title / name (defaults to 'title')
 * page url (defaults to 'slug_url' e.g. /about/ethos)
 * 
 * Optional Fields
 * ------------------
 * title_for_navigation
 * redirect_url
 * redirect_target
 * 
 * Example data
 * ------------------
 * [Article] =&gt; Array
                (
                    [name] =&gt; Find out about us
                    [slug_url] =&gt; /about-us
                    [title_for_navigation] =&gt; About Us
                    [redirect_url] =&gt; 
                    [redirect_target] =&gt; 
                    [lft] =&gt; 15
                    [id] =&gt; 105
                    [rght] =&gt; 24
                    [parent_id] =&gt; 
                )
&nbsp;
            [children] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [Article] =&gt; Array
                                (
                                    [name] =&gt; Philosophy
                                    [slug_url] =&gt; /about-us/philosophy
                                    [title_for_navigation] =&gt; 
                                    [redirect_url] =&gt; 
                                    [redirect_target] =&gt; 
                                    [lft] =&gt; 16
                                    [id] =&gt; 111
                                    [rght] =&gt; 21
                                    [parent_id] =&gt; 105
                                )
 * 
 * 
 * 
 *
 * Usage:
 * 
 * Include the helper in your controller as usual.
 * 
 * The helper operates in 2 modes 'tree' (which is default) and 'context'
 * 'tree' will produce a whole list of nested Uls - can be used to generate top level navigation (works well with things like suckerfish)
 * 'context' will only produce nested ULs for the current branch
 * 
 * Using the example above if you were on the /about/ethos page and you wanted the navigation fragment in the sidebar you would use context
 * /about
 * /about/company-history
 * /about/company-history/gallery
 * /about/ethos
 * /about/vacancies
 * 
 * In a view / element to generate complete menu
 * echo $menu-&gt;setup($menu_data, array('selected' =&gt; $this-&gt;here));
 * 
 * In a view / element to generate a context menu from the same data, set the class of the parent UL
 * echo $menu-&gt;setup($menu_data, array('selected' =&gt; $this-&gt;here, 'type' =&gt; 'context', 'menuClass' =&gt; 'context-menu'));
 * 
 * 
 * In a view / element to generate a sitemap from different data, let the helper know to use the 'Sitemap' model rather than the default 'Article' model and set the parent UL class.
 * $sitemap = new MenuHelper();
 * echo $sitemap-&gt;setup($data,  array('modelName' =&gt; 'Sitemap', 'menuClass' =&gt; 'sitemap'));
 * 
 * Version Details
 * 
 * 1.0
 * + Initial release.
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> MenuHelper <span style="color: #000000; font-weight: bold;">extends</span> AppHelper <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Current page in application
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/** Internal variable for the data
	 *
	 * @var array
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Default css class applied to the menu
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$menuClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'menu'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Default DOM id applied to menu
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$menuId</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'top-menu'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * CSS class applied to the selected node and its parent nodes 
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$selectedClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'selected'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * CSS class applied to the exact selected node in the tree - in addition to $selectedClass
	 *
	 * @var unknown_type
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$selectedClassItem</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'item-selected'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Default Slug
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$defaultSlug</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'home'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Type of menu to be generated:
	 * 'tree' - to generate a complete tree
	 * 'context' - to only render the specific barnch under the current page
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'tree'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Model name used in $array e.g. $data[0]['Article']['name']
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$modelName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Article'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Database column name - (i.e. a shorter version of the name / title for use only in naviagtion)
	 * e.g. A page called 'Welcome to the giant flea circus' 
	 * might be set to show up on navigation as 'home'
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$titleForNavigation</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'title_for_navigation'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Database column name for title / name
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'name'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Database column name for complete page slug e.g. /about/history/early-years
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$slugUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'slug_url'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Database column name for redirect_url for instance if /about/blog redirects to http://blog.somewebsite.com
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$redirectUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'redirect_url'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Target for redirect (see redirectUrl)
	 *
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$redirectTarget</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'redirect_target'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Minumum number of items required to render a context menu
	 *
	 * @var int
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$contextMinLength</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Internal Counter used in type: 'context'
	 *
	 * @var int
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$li_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Internal flag to see if the page has been matched to an item
	 *
	 * @var bool
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$matched</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Internal counter
	 *
	 * @var int
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Enter description here...
	 *
	 * @var unknown_type
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$rootNode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setOption<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getOption<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Setup the helper and return a string to echo
	 *
	 * @param array $array Data array containing the lists
	 * @param array $config Configuration variables to override the defaults
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// update and override the default variables </span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// set the default slug selected if the current page does not match</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selected</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selected</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaultSlug</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">// get the root node of the selected tree if this a context menu</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'context'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rootNode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRootNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selected</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildMenu</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if the current page has matched one of the links in the tree</span>
		<span style="color: #666666; font-style: italic;">// then get rid of the 'default_slected' placeholder</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matched</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default_selected'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectedClass</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default_selected'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if this is a context menu, it looks daft if it only has 1 item </span>
		<span style="color: #666666; font-style: italic;">// if this is the case hide it</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'context'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">li_count</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contextMinLength</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&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><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Call the menu iterator method and if it returns a string warp it up in a UL
	 *
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> buildMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">menuIterator</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;ul  id=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">menuId</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; class=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">menuClass</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Explode a url slug and get the root page
	 *
	 * @param string $string 
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> getRootNode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$rootNode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// $node[0] will always be empty becuase the first char of $this-&gt;selected will always be '/'</span>
				<span style="color: #000088;">$rootNode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$rootNode</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Recursive method to loop down through the data array building menus and sub menus
	 *
	 * @param array $array
	 * @param int $depth
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> menuIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$is_selected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$continue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sub</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'context'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRootNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slugUrl</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rootNode</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$continue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$continue</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// if this is the first list item set default_selected placeholder</span>
				<span style="color: #000088;">$default_selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$default_selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'default_selected'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'children'</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>
					<span style="color: #000088;">$sub</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$sub</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">menuIterator</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'children'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$sub</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>	
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selected</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slugUrl</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// this is the selected item or a parent node of the selected item</span>
						<span style="color: #000088;">$selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectedClass</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$is_selected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matched</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selected</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slugUrl</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// this is the exact selected item</span>
					<span style="color: #000088;">$selected</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectedClass</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectedClassItem</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// keep track if this is a contextual menu </span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'context'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">li_count</span><span style="color: #339933;">++;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
				<span style="color: #666666; font-style: italic;">// Get the name / title to be used for the link text</span>
				<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// Get the URL / target for the link</span>
				<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$selected</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$default_selected</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a  href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</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;">'&quot; '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'target'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&gt;&lt;span&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/span&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$sub</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Look in the data and check if this is a straight url
	 * or whether it is actually a redirect
	 *
	 * @param array $var
	 * @return array
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> getUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectUrl</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectUrl</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>
				<span style="color: #000088;">$url</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: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectUrl</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectTarget</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectTarget</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>
					<span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'target'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' target=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectTarget</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$url</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: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slugUrl</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'target'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * See if there is a title_for_navigation 
	 *
	 * @param array $var
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> getName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titleForNavigation</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titleForNavigation</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>
			<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titleForNavigation</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/09/29/cakephp-menu-helper-for-tree-data/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Sneak Preview</title>
		<link>http://www.flipflops.org/2009/09/11/sneak-preview/</link>
		<comments>http://www.flipflops.org/2009/09/11/sneak-preview/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:51:02 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/09/11/sneak-preview/</guid>
		<description><![CDATA[At the moment I&#8217;m working on an e-commerce project using the Amazon Product Advertising API. The website is called www.science-fictions.co.uk, and as the name suggests its theme is Science Fiction Books and Fantasy Literature. The project is built on my brand new CakePHP based CMS system and the Tarzan AWS library which makes connecting to [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment I&#8217;m working on an e-commerce project using the Amazon Product Advertising API. The website is called <a href="http://www.science-fictions.co.uk">www.science-fictions.co.uk</a>, and as the name suggests its theme is <a href="http://www.science-fictions.co.uk">Science Fiction Books</a> and Fantasy Literature. </p>
<p>The project is built on my brand new CakePHP based CMS system and the <a href="http://tarzan-aws.com/">Tarzan AWS</a> library which makes connecting to and utilizing Amazon web services, whilst not a breeze, rather enjoyable.</p>
<p>The website is hurtling along at an astonishing rate and with any luck, the first version should be up and live early next week.</p>
<p><a href="http://www.science-fictions.co.uk"><img src='http://www.flipflops.org/wp-content/uploads/2009/09/screen.jpg' alt='www.Science-Fictions.co.uk - Books for Sci Fi and Fantasy lovers' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/09/11/sneak-preview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Things to come</title>
		<link>http://www.flipflops.org/2009/08/19/things-to-come/</link>
		<comments>http://www.flipflops.org/2009/08/19/things-to-come/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 22:27:52 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Thoughtful]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/08/19/things-to-come/</guid>
		<description><![CDATA[A bit of a taster really, a post about the things that I intend to write &#8211; well that&#8217;s one way of getting me to ensure that I do write them. NestedListHelper I&#8217;ve written a helper to generate nested UL&#8217;s from the results of a find(&#8216;threaded&#8217;) call. I&#8217;ve been using the helper to generate the [...]]]></description>
			<content:encoded><![CDATA[<p>A bit of a taster really, a post about the things that I intend to write &#8211; well that&#8217;s one way of getting me to ensure that I do write them.</p>
<p><strong>NestedListHelper</strong><br />
I&#8217;ve written a helper to generate nested UL&#8217;s from the results of a find(&#8216;threaded&#8217;) call. I&#8217;ve been using the helper to generate the nested lists for CSS menus and it is also great for sitemaps. Just needs a bit of tidying up before I set it free.</p>
<p><strong>Back to basics with Auth</strong><br />
(This one is actually in draft right now) Another CakePHP one &#8211; I&#8217;ve been using a quite complex auth / groups / users solution derived the fabulous solution by <a href="http://www.studiocanaria.com/articles/cakephp_auth_component_users_groups_permissions">Studio Canaria</a> but these things get more and more complex. Recently for a project I just needed something simple but I&#8217;d forgotten how complex and powerful even basic Auth can be, so I decided to write a kind of back to basics tutorial.</p>
<p><strong>My perfect E-book</strong><br />
I love books. I hate reading PDFs or anything book-like of the screen. My thoughts on the perfect E-book reader.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/08/19/things-to-come/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A quick vaguely Cakey post</title>
		<link>http://www.flipflops.org/2009/08/01/a-quick-vaguely-cakey-post/</link>
		<comments>http://www.flipflops.org/2009/08/01/a-quick-vaguely-cakey-post/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 20:37:44 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/08/01/a-quick-vaguely-cakey-post/</guid>
		<description><![CDATA[Not a real post this really, more of a snippet, but something of interest. I just switched on view cacheing for my UK Business Directory (a personal project of mine) and by my rough and ready benchmarking with firebug the load times increased by 75%. The site is hosted on Dreamhost which whilst great value [...]]]></description>
			<content:encoded><![CDATA[<p>Not a real post this really, more of a snippet, but something of interest. I just switched on view cacheing for my <a href="http://www.blinks.org.uk">UK Business Directory</a> (a personal project of mine) and by my rough and ready benchmarking with firebug the load times increased by 75%. The site is hosted on Dreamhost which whilst great value for money and very featureful isn&#8217;t always the fastest of hosts, so it has made a real difference.</p>
<p>I&#8217;ve also just added fulltext search to the site &#8211; its slightly unusual in that it searches two tables at either end of a HABTM relationship, when I get the time I&#8217;m planning to write a quick post about setting that up with CakePHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/08/01/a-quick-vaguely-cakey-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two CakePHP behaviours to extend MeioUpload</title>
		<link>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/</link>
		<comments>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:53:24 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/</guid>
		<description><![CDATA[I&#8217;ve been using the the Meio Upload Behaviour for a while as its a very handy piece of code, but as is so often the case it doesn&#8217;t do quite what I need. In the past I&#8217;ve got round this by hacking together a kind of supporting framework in app_controller and scattered about in my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the the <a href="http://www.meiocodigo.com/projects/meioupload/">Meio Upload Behaviour</a> for a while as its a very handy piece of code, but as is so often the case it doesn&#8217;t do quite what I need. In the past I&#8217;ve got round this by hacking together a kind of supporting framework in app_controller and scattered about in my models. But the other day I came across the <a href="http://github.com/jrbasso/MeioUpload/tree/master">newest version of the code by Juan Basso  on Github</a> and decided to dump my mess of spaghetti code and start from scratch.</p>
<h2>Aims</h2>
<p>The idea is that each model can have its own uploads with their own defaults, for example: </p>
<ul>
<li>Products might need to generate images at 3 different sizes with the smallest zoom cropped.</li>
<li>News items might have 2 image sizes but also need to upload a PDF press release.</li>
</ul>
<p>All of the uploaded files can be viewed and managed centrally from the Upload model.</p>
<p>The changes I wanted to make were as follows:</p>
<ol>
<li>Use a single Uploads table attached to multiple models (<a href="http://bakery.cakephp.org/articles/view/polymorphic-behavior">using the Polymorphic behaviour</a>)</li>
<li>The ability to do multiple uploads at once</li>
<li>Rename my uploaded files</li>
<li>Have an UploadVariants model / table with meta information about the thumbnails</li>
<li>Be able to use more of the PHPThumb image options and use them on a per thumbnail basis.</li>
</ol>
<p>Rather than just take the behaviour and start writing on top of it, I decided to extend the original behaviour (yes you can do this in CakePHP &#8211; its just easy to get absorbed in the framework and forget it) and then create an additional behaviour that manages the multiple uploads.</p>
<p>The underlying requirements are quite simple:</p>
<ul>
<li><a href="http://www.meiocodigo.com/projects/meioupload/">Meio Upload Behaviour</a></li>
<li><a href="http://bakery.cakephp.org/articles/view/phpthumb-component">Nate Constant’s phpThumb Component </a></li>
<li><a href="http://bakery.cakephp.org/articles/view/polymorphic-behavior"><strike>Polymorphic Behaviour</strike></a></li>
<li><a href="http://phpthumb.sourceforge.net/">PHPThumb</a></li>
</ul>
<p>(<strong>Note 09/07/2009</strong> you don&#8217;t actually need the Polymorphic Behaviour, unless you want to do fancy things with your finds)</p>
<p>And my two new behaviours:</p>
<ul>
<li><a href="http://www.flipflops.org/example/je_meio_upload.php.txt">je_meio_upload.php</a></li>
<li><a href="http://www.flipflops.org/example/je_meio_upload_polymorphic.php.txt">je_meio_upload_polymorphic.php</a></li>
</ul>
<p><strong>At the end of the article is a link to let you download a zipped working CakePHP app with everything in place</strong></p>
<h2>The models</h2>
<p>First things first. The database tables on which my models are based.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
MySQL Backup
Source Host:           localhost
Source Server Version: 5.0.51b-community-nt
Source Database:       je_meio
Date:                  2009/06/29 15:39:15
*/</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> FOREIGN_KEY_CHECKS<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>;
#<span style="color: #808080; font-style: italic;">----------------------------</span>
# <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">STRUCTURE</span> <span style="color: #993333; font-weight: bold;">FOR</span> products
#<span style="color: #808080; font-style: italic;">----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> products;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`products`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`title`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;
&nbsp;
#<span style="color: #808080; font-style: italic;">----------------------------</span>
# <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">STRUCTURE</span> <span style="color: #993333; font-weight: bold;">FOR</span> upload_variants
#<span style="color: #808080; font-style: italic;">----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> upload_variants;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`upload_variants`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`upload_id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`variant`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filename`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`quick_type`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`width`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`height`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;
&nbsp;
#<span style="color: #808080; font-style: italic;">----------------------------</span>
# <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">STRUCTURE</span> <span style="color: #993333; font-weight: bold;">FOR</span> uploads
#<span style="color: #808080; font-style: italic;">----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> uploads;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`uploads`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`class`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'Upload'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`foreign_id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`alt`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filename`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`dir`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`mimetype`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`quick_type`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filesize`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`position`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`height`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`width`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`processed`</span> tinyint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`class`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`class`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`foreign_id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">class</span> Upload <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//The Associations below have been created with all possible keys, those that are not needed can be removed</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'UploadVariant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'UploadVariant'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'upload_id'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'dependent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'exclusive'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'finderQuery'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'counterQuery'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$actsAs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Polymorphic'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'JeMeioUpload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files/uploads'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'create_directory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'max_size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2097152</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'max_dimension'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'w'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'thumbnailQuality'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'useImageMagick'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'imageMagickPath'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/usr/bin/convert'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'allowed_mime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'image/gif'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/pjpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'allowed_ext'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.jpg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'thumbsizes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'small'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'medium'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">220</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">220</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'large'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">800</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'default_class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'random_filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
         <span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the Upload model, just include the Polymorphic behaviour and JeMeioUpload instead of MeioUpload. You could actually use the same defaults as the MeioUpload behaviour itself but there are two additional defaults  <em>&#8216;default_class&#8217; => &#8216;Upload&#8217;</em>, and <em>&#8216;random_filename&#8217; => true</em>. These both refer to renaming files. As the behaviour can be used to manage uploads from multiple models in a single table it allows you to set the default Upload model. You can also set whether or not you want the files to have the meaningful part replaced with a random string.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UploadVariant <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UploadVariant'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//The Associations below have been created with all possible keys, those that are not needed can be removed</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$belongsTo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Upload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'upload_id'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The UploadVariant Model is just as it was baked.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Product <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Product'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$validate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notempty'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'Upload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>    
            <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'foreign_id'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'dependent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload.position ASC'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$actsAs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
     <span style="color: #0000ff;">'JeMeioUploadPolymorphic'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$jeMeioUploadParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files/uploads/'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'create_directory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'allowed_mime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/pjpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'allowed_ext'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.jpg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'thumbsizes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'small'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'large'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">800</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'shop'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">265</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">265</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'random_filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Product is a test model set up to demonstrate the multiple uploads and the Polymorphic association to the Upload model. In this case the meaningful part of the filenames will not be replaced with a random string and the &#8216;small&#8217; thumbnail will be zoom cropped. To find out more about <em>image_options</em> you will need to check the PHPThumb component and the documentation PHPThumb itself (play about and experiment) &#8211; what you can and can&#8217;t do will also be effected by whether or not you have ImageMagick on your server.</p>
<h2>The Controllers</h2>
<p>You don&#8217;t need to make any changes to your controllers at all.</p>
<h2>The Views</h2>
<p>There is nothing complicated in the views at all. Just remember to set them up properly for uploads.</p>
<h3>The uploads/add.ctp</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;fieldset&gt;
 		&lt;legend&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/legend&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/fieldset&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>The products/add.ctp</h3>
<p>This view allows up to 3 uploads to be stored in the associated Upload model.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;fieldset&gt;
 		&lt;legend&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/legend&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.0.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.1.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.3.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/fieldset&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h2>Summary</h2>
<p>The one part I&#8217;m not terribly happy with at the moment is error messages returning to the views in the Polymorphic associations (e.g. Product example). At the moment if an image or upload can&#8217;t be processed then there is no warning or error message. At the moment this is compromise I&#8217;m willing to live with. </p>
<p>I could certainly build some kind of component scaffold or something to go in the controllers to return an error message but I think the gain in responsiveness would probably be outweighed by the added complexity. Right now I can&#8217;t figure out an elegant way to get error messages from back to the views &#8211; if anybody has any suggestions please let me know.<br />
(<strong>Note</strong> if you are uploading straight into the Upload model then the error messages are unaffected)</p>
<p>There is also the problem of what do you do when in a situation like the following: If you add a new Product successfully but the associated upload has problems? Ideally you would want to redirect to the edit view for that Product but there seems to be no easy way of doing this from a Model / Behaviour.</p>
<p>One solution that I have implemented in the past is to create dedicated views for uploading &#8211; so if you do hack your hacks are easy to manage.</p>
<p><strong>I&#8217;ve baked a quick and dirty demo that you can download <a href="http://www.flipflops.org/example/je_meio_upload.zip">here</a></strong>. Its so basic that it doesn&#8217;t even show the uploaded images!</p>
<h2>Todo List</h2>
<ul>
<li>
A helper to generate things like uploads fields complete with delete checkboxes and thumbnail images.</li>
<li>
Deleting the via the Polymorphic association  (don&#8217;t think this works right now)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>New business directory seeks businesses</title>
		<link>http://www.flipflops.org/2009/06/17/new-business-directory-seeks-businesses/</link>
		<comments>http://www.flipflops.org/2009/06/17/new-business-directory-seeks-businesses/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 11:41:41 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Things]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/06/17/new-business-directory-seeks-businesses/</guid>
		<description><![CDATA[I&#8217;ve been working on a business directory website in my spare time for a while and it is now live. The directory is www.blinks.org.uk and is for for companies / organisations / individuals based in the UK who want to promote their businesses. It is totally free to register and you won&#8217;t find any registration [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a business directory website in my spare time for a while and it is now live. The directory is <a href="http://www.blinks.org.uk"><strong>www.blinks.org.uk</strong></a> and is for for companies / organisations / individuals based in the UK who want to promote their businesses. It is totally free to register and you won&#8217;t find any registration details sold or passed on to anybody!</p>
<p>At the moment it is still very much in a testing stage and I&#8217;m after feedback. Comments suggestions etc. would be greatly appreciated.</p>
<p>The site is written with the wonderful CakePHP framework (and god bless view caching)</p>
<p><a href="http://www.blinks.org.uk"><img src='http://www.flipflops.org/wp-content/uploads/2009/06/blinks4.gif' alt='blinks.org.uk - Free UK business directory' /></a></p>
<p><strong>Tell me more&#8230;</strong></p>
<p>The sign up process is quick and easy and only requires that you confirm the email address you register with (this email remains private and is not displayed on the site). </p>
<p>When you have registered you can add as many businesses as you want. You can add the following information for each business you add:</p>
<ul>
<li>Company name</li>
<li>Website Address</li>
<li>Contact Details<br /><small>These are mandatory, although you can elect not to show them on the website</small></li>
<li>Summary</li>
<li>Long Description</li>
<li>Image or Logo</li>
<li>List your business in up to 5 Categories</li>
</ul>
<p><a href="http://www.blinks.org.uk/users/register">Click here to register today!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/06/17/new-business-directory-seeks-businesses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Overload $this-&gt;tags &amp; $this-&gt;map in Apphelper</title>
		<link>http://www.flipflops.org/2009/05/23/overload-this-tags-this-map-in-apphelper/</link>
		<comments>http://www.flipflops.org/2009/05/23/overload-this-tags-this-map-in-apphelper/#comments</comments>
		<pubDate>Sat, 23 May 2009 10:13:13 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/05/23/overload-this-tags-this-map-in-apphelper/</guid>
		<description><![CDATA[CakePHP is full of amazingly handy little bits and pieces, the trick is discovering them by exploring the API or paying attention to people who know Cake inside out. AppHelper sits there begging to be filled, the idea being that you can overload core helper methods here; however there is a lot of debate as [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP is full of amazingly handy little bits and pieces, the trick is discovering them by exploring the API or paying attention to people who know Cake inside out.</p>
<p>AppHelper sits there begging to be filled, the idea being that you can overload core helper methods here; however there is a lot of debate as to whether or not this is actually a good approach and whether it is infact better (safer?) to overload helpers on a case by case basis (e.g. MyFormhelper extends FormHelper). (Personally I think it would be great to have the core helpers moved into base helpers so you can overload the core methods and still refer to them easily (e.g. HtmlHelper extends BaseHtmlhelper extends AppHelper, where HtmlHelper becomes an empty Class) </p>
<p>Two of the things I always have set in AppHelper are as follows:</p>
<p><strong>1. Setup $this->map</strong> how I like it. $map defined in the Formhelper (cake/libs/views/helpers/form.php) is part of the auto magic behind forms. When you create a form in a view, Cake queries the model schema and figures out what sort of field it should generate for each database field.</p>
<p>Whilst I can see the reasoning behind the way Cake generates all the &lt;select&gt; fields, I would much rather have Cake genearte a simple &lt;text&gt; field and then use a JavaScript date picker to populate the field.</p>
<p>If you take a morning or a day to mess about and customise your bake templates then you can save vast amounts of time &#8211; if you want a date field why not just have it come to life with all the hooks for your Javascript there already? (A good introduction for custom baking is <a href="http://www.ad7six.com/MiBlog/Blogs/view/CustomBakeTemplates">ad7six&#8217;s post</a>.)</p>
<p><strong>2. Redefine Tags.</strong> One of my real annoyances (and I know this is silly) is the fact that when Cake creates hidden fields it does not flag them with any specific class. This means that styles applied to other &lt;input&gt; fields can easily cascade down and cause odd little lines to appear all over your forms. Often you wouldn&#8217;t even notice this, but once you change the background colour of your form&#8230; all hell can break loose. </p>
<p>Tags are defined in /cake/libs/view/helpers/html.php so a quick and dirty solution is just to wrap a div with class around the hidden inputs so they can easily be distinguised css wise from all the other tags.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AppHelper <span style="color: #000000; font-weight: bold;">extends</span> Helper <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
   * overload the default type mappings is /cake/libs/views/helpers/form.php FormHelper
   */</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$map</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'string'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>    
          <span style="color: #0000ff;">'datetime'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'boolean'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkbox'</span><span style="color: #339933;">,</span>  
          <span style="color: #0000ff;">'timestamp'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'text'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'textarea'</span><span style="color: #339933;">,</span>  
          <span style="color: #0000ff;">'time'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'time'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'date'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> 
          <span style="color: #0000ff;">'float'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
        * overload the default html tags /cake/libs/view/helpers/html.php
        */</span>
        <span style="color: #000088;">$this</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> <span style="color: #0000ff;">'&lt;div class=&quot;hidden-input&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;%s&quot; %s/&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you are looking for other things to stick in your AppHelper then try <a href="http://www.pseudocoder.com/archives/2009/03/01/how-to-save-half-a-second-on-every-cakephp-requestand-maintai-reverse-routing/">Matt Curry&#8217;s app_helper url caching</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/05/23/overload-this-tags-this-map-in-apphelper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t add a component twice</title>
		<link>http://www.flipflops.org/2009/02/03/dont-add-a-component-twice/</link>
		<comments>http://www.flipflops.org/2009/02/03/dont-add-a-component-twice/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 19:41:10 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/02/03/dont-add-a-component-twice/</guid>
		<description><![CDATA[Last week I spent an annoyingly long time tracking down a bug caused by what was basically a simple typo. I discovered that my controller redirects (e.g. $this->redirect(array('action'=>'index')); )were failing, but without generating any errors at all (that I could find). Eventually I tracked down the cause by just taking the whole controller apart and [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I spent an annoyingly long time tracking down a bug caused by what was basically a simple typo. </p>
<p>I discovered that my controller redirects (e.g. <code>$this->redirect(array('action'=>'index'));</code> )were failing, but without generating any errors at all (that I could find). </p>
<p>Eventually I tracked down the cause by just taking the whole controller apart and rebuilding it one step at a time &#8211; I was including a component (PhpThumb) in my controller but the component was subsequently being included using App:import within a behaviour.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/02/03/dont-add-a-component-twice/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting the &#8216;admin&#8217; path using $html-&gt;link</title>
		<link>http://www.flipflops.org/2009/02/03/setting-the-admin-path-using-html-link/</link>
		<comments>http://www.flipflops.org/2009/02/03/setting-the-admin-path-using-html-link/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 19:39:01 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/02/03/setting-the-admin-path-using-html-link/</guid>
		<description><![CDATA[Usually CakePHP can work out when link needs to be within the /admin/ section of your site. Sometimes however it needs a little help. When this happens you need to add 'admin' => true to the list of parameters. 1 2 &#160; echo $html-&#62;link&#40;$data&#91;'SomeModel'&#93;&#91;'name'&#93;, array&#40; 'controller' =&#62; 'some_controller', 'action' =&#62; 'index', 'admin' =&#62; true&#41;&#41;;]]></description>
			<content:encoded><![CDATA[<p>Usually CakePHP can work out when link needs to be within the /admin/ section of your site. Sometimes however it needs a little help. When this happens you need to add <code>'admin' => true</code> to the list of parameters.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SomeModel'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'some_controller'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/02/03/setting-the-admin-path-using-html-link/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

