<?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>Cakephp.nu blog &#187; english</title>
	<atom:link href="http://www.cakephp.nu/t/english/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cakephp.nu</link>
	<description>Cake and cookies by Jippi</description>
	<lastBuildDate>Wed, 11 Aug 2010 09:15:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Yay &#8211; my dell new server is now online :D</title>
		<link>http://www.cakephp.nu/my-new-dell-server-is-now-online</link>
		<comments>http://www.cakephp.nu/my-new-dell-server-is-now-online#comments</comments>
		<pubDate>Wed, 16 Jul 2008 22:15:37 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[lighttpd]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/?p=22</guid>
		<description><![CDATA[
Finally I got the good news from my new hosting company I can hardly wait to get it FreeBSD 7.0 installed on it and setup a nice vhost system with Lighttpd + PostgreSQL. It&#8217;s gonna be awsome. The server I&#8217;m currently using is &#8216;only&#8217; Dual core XEON w/ 3.5Gb ram, and some random SATA drives, [...]
]]></description>
			<content:encoded><![CDATA[<p>Finally I got the good news from my <a href="http://www.logiqit.com">new hosting company</a></p>
<p>I can hardly wait to get it FreeBSD 7.0 installed on it and setup a nice vhost system with Lighttpd + PostgreSQL. It&#8217;s gonna be awsome.<br />
The server I&#8217;m currently using is &#8216;only&#8217; Dual core XEON w/ 3.5Gb ram, and some random SATA drives, so the improvement should be huge <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I&#8217;m quite excited, because its going to be my first server ever without Apache and MySQL installed. Or well, atleast until some stupid customer or what not (<a href="http://www.kosmosgrafisk.dk">Biesbjerg</a>?) demands it <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>If I can find the time, I will write a guide on how I&#8217;m going to configure my server (Lighttpd, PostgreSQL, Dovecot + sendmail, quota, fast-cgi php5), it might be useful for someone <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Let me know if it has any interest to you guys <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Specs</h2>
<p>- Dell PE 1950 III<br />
- PE1950 PCIE Riser (2 Slots) 1 S<br />
- <strong>Quad Core Xeon E5410 (2.33GHz, 2x6MB, 1333MHz FSB)</strong> (SMP supported)<br />
- <strong>4GB (2x2GB Dual Rank DIMMs) 667MHz FBD (up to 32 GB)</strong><br />
- <strong>3x 146GB SAS 10k 2.5&#8243; HDPE1950 III 2.5&#8243;</strong> HDD support chassis<br />
- Perc 6i Integrated Controller<br />
- 8X DVD-ROM Drive IDE<br />
- PE1950 III Non-Redundant Power Supply No Power Cord<br />
- TCP/IP Offload Engine 2P<br />
- Broadcom TCP/IP Offload Engine functionality (TOE) Not Enabled<br />
- PE1950 OpenManage kit and FI Driver<br />
- CFI EMEA Service. (SV-Hi) OR PowerEdge, RAID/partition<br />
- RAID 1 Single Container<br />
- RAID 0 (1 HDD)<br />
- Rack Rails Static Rapid 1 S<br />
- PE1950 III &#8211; C2,MSSR0,ADD IN PERC5i/6i/SAS6iR, min 2 / max 2 or 4</p>
<p>/Jippi</p>

	Tags: <a href="http://www.cakephp.nu/t/dell" title="dell" rel="tag">dell</a>, <a href="http://www.cakephp.nu/t/dovecot" title="dovecot" rel="tag">dovecot</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/lighttpd" title="lighttpd" rel="tag">lighttpd</a>, <a href="http://www.cakephp.nu/t/news" title="news" rel="tag">news</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/my-new-dell-server-is-now-online/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>open_basedir will slow you down &#8211; security vs. speed</title>
		<link>http://www.cakephp.nu/open_basedir-will-slow-you-down-security-vs-speed</link>
		<comments>http://www.cakephp.nu/open_basedir-will-slow-you-down-security-vs-speed#comments</comments>
		<pubDate>Fri, 21 Mar 2008 01:48:58 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/open_basedir-will-slow-you-down-security-vs-speed</guid>
		<description><![CDATA[
Just a quickie. I’m working on some security enhancements for my new website project, and in that progress, I have moved away from Apache2.2.3 and now using Lighttpd instead. Lighttpd does not use the same method of invoking php as apache does (mod_php vs. fast-cgi php). In my eager to make the application as secure [...]
]]></description>
			<content:encoded><![CDATA[<p>Just a quickie.</p>
<p>I’m working on some security enhancements for my new website project, and in that progress, I have moved away from Apache2.2.3 and now using Lighttpd instead. Lighttpd does not use the same method of invoking php as apache does (mod_php vs. fast-cgi php).</p>
<p>In my eager to make the application as secure and locked down as possible, I went berserk in the php-cgi.ini file and turned on just about any security feature I could find (not safemode!), including the innocent looking switch called “open_basedir”.</p>
<p>That was rather late in the night, so when I resumed my work the following day, I have long forgotten about all the fancy security settings I had enabled in php. </p>
<p>A few hours ago I noticed that the complete render time for the front page suddenly was ~2seconds(!) &#8211; and comparing with apache’s load time for the same page (0.9s) I was quite disappointed at lighttpd and fastcgi, but refused to give up my new found love without a fair trial.</p>
<p>I attacked google with full force without finding any useful resources that might be able to explain my issue.. I was quite sure it was APC that did not function well in a fastcgi environment &#8211; and therefore my google madness was focused around the keywords “apc + fastcgi”  </p>
<p>While chatting to PatrickDK in the #lighttpd channel @ freenode, it suddenly hit me &#8211; let’s try to disable everything I have “fixed” last night &#8211; starting with XDebug, some 3rd party php modules (syck, memcache, simplexml, fileinfo) &#8211; and then, open_basedir flag.</p>
<p><b>And with just one line commented out in my php-cgi.ini file, the render time went from 2.4 to 0.5 seconds !!(!!) </b></p>
<p>So just a little note to you guys out there, beware of the open_basedir setting in a setup where you include many files, it is a rather costly feature to use. And when running fastcgi php in chroot()ed setup, its not really required anyway  </p>
<p><b>Its another +1 for lighty and fastcgi</b></p>
<p>And yes, I’m aware that open_basedir is slow because it has to validate EVERY file or path you work with inside php to check if its within the scope defined.</p>

	Tags: <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/lighttpd" title="lighttpd" rel="tag">lighttpd</a>, <a href="http://www.cakephp.nu/t/php" title="php" rel="tag">php</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/open_basedir-will-slow-you-down-security-vs-speed/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New books from amazon.co.uk</title>
		<link>http://www.cakephp.nu/books-amazoncouk</link>
		<comments>http://www.cakephp.nu/books-amazoncouk#comments</comments>
		<pubDate>Wed, 19 Mar 2008 21:20:19 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/books-amazoncouk</guid>
		<description><![CDATA[
Just got an email from Amazon.co.uk &#8211; the have shipped my new batch of dev-books This time around it was more an impulze to buy some books, so I hope I will end up as satisfied as last time I purchased some books from them. Building Scalable Web Sites: Building, scaling, and optimizing the next [...]
]]></description>
			<content:encoded><![CDATA[<p>Just got an email from Amazon.co.uk &#8211; the have shipped my new batch of dev-books <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This time around it was more an impulze to buy some books, so I hope I will end up as satisfied as last time I purchased some books from them.</p>
<ul>
<li><a target="_blank" href="http://www.amazon.co.uk/exec/obidos/ASIN/0596102356">Building Scalable Web Sites: Building, scaling, and optimizing the next generation of web applications</a></li>
<li><a target="_blank" href="http://www.amazon.co.uk/exec/obidos/ASIN/0596529260">RESTful Web Services</a></li>
<li><a target="_blank" href="http://www.amazon.co.uk/exec/obidos/ASIN/0596529309">High Performance Web Sites: Essential Knowledge for Front-End Engineers: Essential Knowledge for Front-end Engineers</a></li>
<li><a target="_blank" href="http://www.amazon.co.uk/exec/obidos/ASIN/0672327562">PostgreSQL (Developers Library)</a></li>
<li><a target="_blank" href="http://www.amazon.co.uk/exec/obidos/ASIN/097584198X">The CSS Anthology: 101 Essential Tips, Tricks and Hacks</a></li>
</ul>
<p>I will probably give a short review of the books once I have read them <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

	Tags: <a href="http://www.cakephp.nu/t/amazon" title="amazon" rel="tag">amazon</a>, <a href="http://www.cakephp.nu/t/books" title="books" rel="tag">books</a>, <a href="http://www.cakephp.nu/t/css" title="css" rel="tag">css</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/php" title="php" rel="tag">php</a>, <a href="http://www.cakephp.nu/t/postgresql" title="postgresql" rel="tag">postgresql</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/books-amazoncouk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster Page Loads &#8211; Bundle Your CSS and Javascript with lighttpd</title>
		<link>http://www.cakephp.nu/faster-page-loads-bundle-your-css-and-javascript-lighttpd-mod_magnet-lua</link>
		<comments>http://www.cakephp.nu/faster-page-loads-bundle-your-css-and-javascript-lighttpd-mod_magnet-lua#comments</comments>
		<pubDate>Tue, 18 Mar 2008 15:23:40 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[lua]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[mod_magnet]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/lighttpd-mod_magnet-written-lua-concat-script</guid>
		<description><![CDATA[
Hello again, Preface This time I have been busy playing with Lighttpd and mod_magnet. I found a blog post where darix mentions a post from sitepoint where they demostrate a technique to speed up the HTTP GET of javascript and CSS files. Its quite simple really, instead of doing &#38;lt;link href=&#34;/css/styles1.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; /&#38;gt; &#38;lt;link [...]
]]></description>
			<content:encoded><![CDATA[<p>Hello again,</p>
<h3>Preface</h3>
<p>This time I have been busy playing with <a target="_blank" href="http://www.lighttpd.net/">Lighttpd</a> and <a target="_blank" href="http://trac.lighttpd.net/trac/wiki/Docs:ModMagnet">mod_magnet</a>. I found <a target="_blank" href="http://nordisch.org/2007/4/10/hah-it-s-not-only-me">a blog post </a>where <a target="_blank" href="http://nordisch.org/">darix </a> mentions a post from sitepoint where they demostrate <a target="_blank" href="http://www.sitepoint.com/blogs/2007/04/10/faster-page-loads-bundle-your-css-and-javascript/">a technique to speed up the HTTP GET of javascript and CSS files</a>. </p>
<p>Its quite simple really, instead of doing</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&amp;lt;link href=&quot;/css/styles1.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;
&amp;lt;link href=&quot;/css/styles2.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;
&amp;lt;link href=&quot;/css/styles3.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;</pre></div></div>

<p>you simply do</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&amp;lt;link href=&quot;/css/styles1.css,styles2.css,styles3.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;</pre></div></div>

<p>and then this script will automagic concat them together into one big file, and make lighty serve that one instead. (The same goes for javascript files, or anything really)</p>
<p>This could save ALOT of HTTP GET&#8217;s to your server, and increase the overall loadtime and performance of your site alot, especially if you use alot of Web2.0 stuff <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>However, the Lua source for their script was not made public, so nobody could benifit from their otherwise impressive speed gains. <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Until now.. or, well, almost &#8211; its not their script, but my own attempt to mimic what they did in pure <a target="_blank" href="http://www.lua.org/">Lua</a> <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I tried to keep the dependencies down to a minimum, however I decided to use one, md5.<br />
You can find the source <a target="_blank" href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lmd5">here</a> (<a href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/lmd5.tar.gz">5.1</a>, <a href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lmd5.tar.gz">5.0</a>)</p>
<h3>Config</h3>
<dl>
<dt>charset (Line 42)</dt>
<dd>Set it so it matches the headers in your lighttpd.conf file. Must match your mod_compress settings aswell to utilize that feature</dd>
<dt>prefix (Line 43)</dt>
<dd>Could be anything really, its just a mean to &#8220;namespace&#8221; your cached files so you can run the script with multiple configs</dd>
<dt>rootPath (Line 44)</dt>
<dd>The path to look for the files to concat, default should be fine for most  DOC_ROOT/js  and DOC_ROOT/css</dd>
<dt>concatRoot (Line 45)</dt>
<dd>The folder to store the concated files, can be anywhere <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </dd>
</dl>
<h3>Setup</h3>
<ul>
<li>Put the source below somewhere on your disk, I asume you name it bundle.lua</li>
<li>Enable mod_magnet in lighttpd.conf</li>
<li>Add <u>magnet.attract-physical-path-to = ( &#8220;YOUR_PATH/bundle.lua&#8221; )</u> to your config where needed</li>
<li>Restart lighttpd</li>
<li>Modify your css/js links to utilize the new feature:)</li>
</ul>
<p>Optimal you can enable mod_compress aswell, bundle.lua works out of the box with any other lighttpd module you may have <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Source</h3>
<p><a target="_blank" href="http://www.cakephp.nu/files/mod_magnet/bundle_0.1.lua">download source</a></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
</pre></td><td class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">--- get stat information on a path</span>
<span style="color: #808080; font-style: italic;">-- @param path to stat</span>
<span style="color: #808080; font-style: italic;">-- @param the ftype to return</span>
<span style="color: #808080; font-style: italic;">-- @return false if ftype or path does not exist</span>
<span style="color: #b1b100;">function</span> file_info<span style="color: #66cc66;">&#40;</span>path, ftype<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">local</span> attr <span style="color: #66cc66;">=</span> lighty.stat<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">if</span> attr <span style="color: #b1b100;">and</span> attr<span style="color: #66cc66;">&#91;</span>ftype<span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">then</span>
        <span style="color: #b1b100;">return</span> attr<span style="color: #66cc66;">&#91;</span>ftype<span style="color: #66cc66;">&#93;</span>
    <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">false</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--- Wrapper for reading a full file into a string</span>
<span style="color: #808080; font-style: italic;">-- @param filename Full path to the file</span>
<span style="color: #808080; font-style: italic;">-- @return a string with the content of the file</span>
<span style="color: #b1b100;">function</span> read_file<span style="color: #66cc66;">&#40;</span>filename<span style="color: #66cc66;">&#41;</span> 
    <span style="color: #b1b100;">local</span> content <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #b1b100;">if</span> file_info<span style="color: #66cc66;">&#40;</span>filename, <span style="color: #ff0000;">&quot;is_file&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
        <span style="color: #b1b100;">local</span> file <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">io.open</span><span style="color: #66cc66;">&#40;</span>filename, <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span>
        content <span style="color: #66cc66;">=</span> file:<span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;*a&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">io.close</span><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">return</span> content
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--- Wrapper for writeing content to a file</span>
<span style="color: #808080; font-style: italic;">-- @param filename Full path to the destionation file</span>
<span style="color: #808080; font-style: italic;">-- @param content The string to write</span>
<span style="color: #b1b100;">function</span> write_cache<span style="color: #66cc66;">&#40;</span>filename, content<span style="color: #66cc66;">&#41;</span> 
    <span style="color: #b1b100;">local</span> file <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">io.open</span><span style="color: #66cc66;">&#40;</span>filename, <span style="color: #ff0000;">&quot;w&quot;</span><span style="color: #66cc66;">&#41;</span>
    file:<span style="color: #b1b100;">write</span><span style="color: #66cc66;">&#40;</span>content<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">io.close</span><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--- Concat multiple files into one file </span>
<span style="color: #808080; font-style: italic;">-- @param lighty lighty global variable passed to the method</span>
<span style="color: #808080; font-style: italic;">-- @param match The files that will be concat into a file</span>
<span style="color: #808080; font-style: italic;">-- @param fileExtension Do !NOT! include the dot ( . )</span>
<span style="color: #b1b100;">function</span> combine_files<span style="color: #66cc66;">&#40;</span>lighty, files, fileExtension<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">require</span> <span style="color: #ff0000;">&quot;md5&quot;</span> 
&nbsp;
    <span style="color: #b1b100;">local</span> charset       <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;; charset=utf-8&quot;</span>
    <span style="color: #b1b100;">local</span> prefix        <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;cache-&quot;</span>
    <span style="color: #b1b100;">local</span> rootPath      <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. fileExtension .. <span style="color: #ff0000;">&quot;/&quot;</span>
    <span style="color: #b1b100;">local</span> concatRoot     <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/tmp/cache/&quot;</span>
    <span style="color: #b1b100;">local</span> lastModified  <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
&nbsp;
    <span style="color: #b1b100;">for</span> file <span style="color: #b1b100;">in</span> <span style="color: #b1b100;">string</span>.gmatch<span style="color: #66cc66;">&#40;</span>files, <span style="color: #ff0000;">&quot;(.-<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span> .. fileExtension .. <span style="color: #ff0000;">&quot;),?&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">do</span>
        <span style="color: #b1b100;">local</span> fullPath <span style="color: #66cc66;">=</span> rootPath .. file
        modTime <span style="color: #66cc66;">=</span> file_info<span style="color: #66cc66;">&#40;</span>fullPath, <span style="color: #ff0000;">&quot;st_mtime&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">type</span><span style="color: #66cc66;">&#40;</span>modTime<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;number&quot;</span> <span style="color: #b1b100;">then</span>
            lastModified <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math.max</span><span style="color: #66cc66;">&#40;</span>lastModified, modTime<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">end</span>            
     <span style="color: #b1b100;">end</span>
&nbsp;
     <span style="color: #b1b100;">local</span> hash <span style="color: #66cc66;">=</span> lastModified .. <span style="color: #ff0000;">&quot;-&quot;</span> .. md5.sumhexa<span style="color: #66cc66;">&#40;</span>files<span style="color: #66cc66;">&#41;</span>
     lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Etag&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'&quot;'</span> .. hash ..<span style="color: #ff0000;">'&quot;'</span>
&nbsp;
    <span style="color: #b1b100;">local</span> cacheFile <span style="color: #66cc66;">=</span> prefix .. hash .. <span style="color: #ff0000;">'.'</span> .. fileExtension
    <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> file_info<span style="color: #66cc66;">&#40;</span>concatRoot .. cacheFile, <span style="color: #ff0000;">&quot;is_file&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
        <span style="color: #b1b100;">local</span> content <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
        <span style="color: #b1b100;">for</span> file <span style="color: #b1b100;">in</span> <span style="color: #b1b100;">string</span>.gmatch<span style="color: #66cc66;">&#40;</span>match, <span style="color: #ff0000;">&quot;(.-<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span> .. fileExtension .. <span style="color: #ff0000;">&quot;),?&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">do</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot;/**<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot; *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot; *  &quot;</span> .. file .. <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot; *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot; */<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            content <span style="color: #66cc66;">=</span> content .. read_file<span style="color: #66cc66;">&#40;</span>rootPath .. file<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">end</span>
        write_cache<span style="color: #66cc66;">&#40;</span>concatRoot .. cacheFile, content <span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">end</span>
    lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> concatRoot .. cacheFile
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> file_info<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;is_file&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    css <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">string</span>.match<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;css/(.*<span style="color: #000099; font-weight: bold;">\.</span>css)&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">if</span> css <span style="color: #b1b100;">then</span>
        <span style="color: #b1b100;">return</span> combine_files<span style="color: #66cc66;">&#40;</span>lighty, css, <span style="color: #ff0000;">&quot;css&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">end</span>
&nbsp;
    js <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">string</span>.match<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;js/(.*<span style="color: #000099; font-weight: bold;">\.</span>js)&quot;</span><span style="color: #66cc66;">&#41;</span>	    
	<span style="color: #b1b100;">if</span> js <span style="color: #b1b100;">then</span>
        <span style="color: #b1b100;">return</span> combine_files<span style="color: #66cc66;">&#40;</span>lighty, js, <span style="color: #ff0000;">&quot;js&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">end</span> 
<span style="color: #b1b100;">end</span></pre></td></tr></table></div>


	Tags: <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/lighttpd" title="lighttpd" rel="tag">lighttpd</a>, <a href="http://www.cakephp.nu/t/lua" title="lua" rel="tag">lua</a>, <a href="http://www.cakephp.nu/t/mod_magnet" title="mod_magnet" rel="tag">mod_magnet</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/faster-page-loads-bundle-your-css-and-javascript-lighttpd-mod_magnet-lua/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>A quick tutorial on CakePHP Set class (Part 1)</title>
		<link>http://www.cakephp.nu/quick-tutorial-cakephp-set-class-part-1</link>
		<comments>http://www.cakephp.nu/quick-tutorial-cakephp-set-class-part-1#comments</comments>
		<pubDate>Mon, 03 Mar 2008 23:56:36 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[set]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/quick-turtorial-cakephp-set-class-part-1</guid>
		<description><![CDATA[
Test data 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 $data = [...]
]]></description>
			<content:encoded><![CDATA[<h3>Test data</h3>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><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: #cc66cc;">1</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_comment_count'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> 
            <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My first title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My first body'</span> 
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">'PostComment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My first comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My first comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My second comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My second comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third comment'</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: #cc66cc;">2</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_comment_count'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
            <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My second title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My second title'</span> 
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">'PostComment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> 
                <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fourth comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fourth comment'</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: #cc66cc;">3</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_comment_count'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
            <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third title'</span> 
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">'PostComment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>                   
&nbsp;
        <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: #000088;">$dataExtra</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
    <span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_comment_count'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
            <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fourth title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fourth title'</span> 
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">'PostComment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fifth comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bdoy'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My fifth comment'</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><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Set::merge</h3>
<p><strong>PHP doc blcok</strong></p>
<pre>
This function can be thought of as a hybrid between PHP's array_merge and
array_merge_recursive. The difference to the two is that if an array key
contains another array then the function behaves recursive (unlike array_merge)
but does not do if for keys containing strings (unlike array_merge_recursive).
See the unit test for more information.         

Note: This function will work with an unlimited amount of arguments and
typecasts non-array parameters into arrays.</pre>
<p>A bit like <a target="_blank" href="http://php.net/array_merge_recursive">array_merge_recursive</a>. Merge joins two arrays on their keys.<br />
If we want to add the <strong>$extraData</strong> array into the <strong>$dat</strong> most people would probably think, hey, lets merge them using Set::merge&#8230; but.. no, dont, unless you know what your doing.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">pr<span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataExtra</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above cod will only produce the &#8216;expected&#8217;(?) result because I have added the numeric key <strong>4</strong> in the $extraData array (Line 40). If I had, as I did the first time around, just let php auto-increment the keys for me, both $datad and $extraData would contain the numeric index key <strong>0</strong>, and since Set::merge works on keys, $extraData&#8217;s <strong>Fourth post</strong> would overwrite $data&#8217;s <strong>First post</strong> where they had anything in common (id, name, post_comment_count, body <strong>and</strong> everything in the first PostComment (My first comment)).</p>
<p>In case I had let php handle the index keys, I would have to use Set::insert to append the fourth comment to the list.</p>
<p>A better use of Set::merge is in CAKE/libs/model/model.php where is automagic merges &#8216;actsAs&#8217; from your current model (PostComment) and your AppModel, so you automagic inherit the global behaviors from AppModel:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// model.php </span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_subclass_of</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'AppModel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$appVars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_class_vars</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AppModel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$merge</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: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>actsAs <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>actsAs <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> 
        <span style="color: #000088;">$merge</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'actsAs'</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>             
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$merge</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> 
        <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;">$appVars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appVars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> Set<span style="color: #339933;">::</span><span style="color: #004000;">merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appVars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A funny thing is that Set::merge is still rarely used in the core code yet. Probably because array_merge (or <strong>am()</strong>) is faster for simple operations like just merging two simple 1 level arrays like a config array.</p>
<h3>Set::filter</h3>
<p><strong>PHP doc blcok</strong></p>
<pre>Filters empty elements out of a route array, excluding '0'.</pre>
<p>This method is <strong>not</strong> recursive. So doing</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;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php 
pr<span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</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;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>wont change anything in the array sinc no elements in first level is empty.</p>
<pre></pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">pr<span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</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;">&#41;</span><span style="color: #339933;">;</span>      
&nbsp;
<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
    <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'post_comment_count'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third title'</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'My third title'</span> 
    <span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We will notice that the PostComment array is gone, since its empty</p>
<h3>Set::pushDiff</h3>
<p><strong>PHP doc blcok</strong></p>
<pre>
Pushes the differences in $array2 onto the end of $array</pre>
<p>That sounds simple enough, and it really is.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">pr<span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">pushDiff</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataExtra</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>just pushes the $dataExtra on the end of $data, since they have nothing in common. Again, this method operates on the array keys when comparing arrays.</p>
<h3>Set::map</h3>
<p><strong>PHP doc block</strong></p>
<pre>
Maps the contents of the Set object to an object hierarchy.
Maintains numeric keys as arrays of objects</pre>
<p>That sounds very fancy, and it is! A lot of people migrating to CakePHP from Symfony (PHPDoctrine, Propel) will probably be confused at first that all model data in CakePHP is arrays, and not objects like other frameworks. This method attemps to &#8216;fix&#8217; this issue by converting a model data array to a set of objects (StdClass). StdClass is a build-in dummy class in PHP, and it doesnt really do anything but contain data, no methods or fancy magic there.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php 
<span style="color: #666666; font-style: italic;">// Convert to objects </span>
<span style="color: #000088;">$map</span> <span style="color: #339933;">=</span> Set<span style="color: #339933;">::</span><span style="color: #004000;">map</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// id of first post (Object style) </span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$map</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>id<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// name of first comment to first post (Object style) </span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$map</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>PostComment<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>name<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// name of first comment to first post (array style) </span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$map</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PostComment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</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: #666666; font-style: italic;">// WONT WORK, Cannot access StdClass as an array</span></pre></td></tr></table></div>

<p>As you can see above, its important to decide what method you want to use, Object or Array style, since they cannot be mixed.<br />
Also, the return from Set::map is a mix of arrays and StdClass, thats why I can access $map[0] as array, but not access $map[0]['name'].</p>
<h3>Set::numeric</h3>
<p><strong>PHP doc blcok</strong></p>
<pre>
Checks to see if all the values in the array are numeric</pre>
<p>Not much to say on this one, because it doesnt do more or less than the name implies.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// false </span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// false </span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// false </span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PostComment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// true </span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>Set<span style="color: #339933;">::</span><span style="color: #004000;">numeric</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>&#8212;&#8212;-</p>
<p>Thats it for now, next time I will look at:</p>
<p>Set::enum, Set::format, Set::extract, Set::insert, Set::remove, Set::check, Set::diff, Set::isEqual, Set::contains, Set::countDim, Set::normalize, Set::combine and Set::reverse.</p>
<p>Look forward to it</p>

	Tags: <a href="http://www.cakephp.nu/t/cakephp" title="Cakephp" rel="tag">Cakephp</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/set" title="set" rel="tag">set</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/quick-tutorial-cakephp-set-class-part-1/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A small change in RSS feeds.</title>
		<link>http://www.cakephp.nu/small-change-rss-feeds</link>
		<comments>http://www.cakephp.nu/small-change-rss-feeds#comments</comments>
		<pubDate>Mon, 03 Mar 2008 22:52:56 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[danish]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/small-change-rss-feeds</guid>
		<description><![CDATA[
Hello again. I have made a small change to the feeds now. Everybody who has subscribed by Feedburner should not notice anything strange. The reason for the change is that I want to be able to blog in Danish too once in a while, and to avoid the &#8216;danish pølsesnak&#8217; for you guys who does [...]
]]></description>
			<content:encoded><![CDATA[<p>Hello again.</p>
<p>I have made a small change to the feeds now. Everybody who has subscribed by Feedburner should not notice anything strange.</p>
<p>The reason for the change is that I want to be able to blog in Danish too once in a while, and to avoid the &#8216;danish pølsesnak&#8217; for you guys who does not understand Danish, I have moved the feed location to include only posts with the &#8216;english&#8217; tag in the future <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://feeds.feedburner.com/CakephpnuBlog">English posts only</a> (Hopefully your using this one right now <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), <a href="http://feeds.feedburner.com/CakephpnuBlogDanish">Danish posts only</a> and <a href="http://feeds.feedburner.com/cakephp/all">Danish+English posts</a></p>
<p>/Jippi</p>

	Tags: <a href="http://www.cakephp.nu/t/danish" title="danish" rel="tag">danish</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/news" title="news" rel="tag">news</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/small-change-rss-feeds/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP talk from FOSDEM &#8211; Free and Open Source Software Developers&#8217; European Meeting</title>
		<link>http://www.cakephp.nu/cakephp-talk-fosdem-free-open-source-software-developers-european-meeting</link>
		<comments>http://www.cakephp.nu/cakephp-talk-fosdem-free-open-source-software-developers-european-meeting#comments</comments>
		<pubDate>Mon, 03 Mar 2008 21:43:13 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[fosdem]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/cakephp-talk-fosdem-free-open-source-software-developers-european-meeting</guid>
		<description><![CDATA[
A small note, gwoo&#8217;s talk from FOSDM 2008 has been made public avilable here together with his slides. Its actually a quite good presentation, too bad he ran out of time in the end Tags: Cakephp, english, fosdem
]]></description>
			<content:encoded><![CDATA[<p>A small note, gwoo&#8217;s talk from <a href="http://www.fosdem.org/">FOSDM 2008</a> has been made <a href="http://ftp.heanet.ie/mirrors/fosdem-video/2008/maintracks/FOSDEM2008-cakephp.ogg">public avilable here</a> together with <a href="http://cakephp.org/files/FOSDEM.pdf">his slides</a>.</p>
<p>Its actually a quite good presentation, too bad he ran out of time in the end <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>

	Tags: <a href="http://www.cakephp.nu/t/cakephp" title="Cakephp" rel="tag">Cakephp</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/fosdem" title="fosdem" rel="tag">fosdem</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/cakephp-talk-fosdem-free-open-source-software-developers-european-meeting/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CakePHP Weekly Summaries Issue #2</title>
		<link>http://www.cakephp.nu/cakephp-weekly-summaries-issue-2</link>
		<comments>http://www.cakephp.nu/cakephp-weekly-summaries-issue-2#comments</comments>
		<pubDate>Mon, 03 Mar 2008 21:37:43 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[weekly summaries]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/cakephp-weekly-summaries-issue-2</guid>
		<description><![CDATA[
Welcome Welcome to the second edition of the CakePHP weekly summaries. Its quite embarrassing that it had to take so long time to get the second editon out. Too long time has passed and the amount of things that has happend during that period is waaay too big to be covered here. Therefor I present [...]
]]></description>
			<content:encoded><![CDATA[<h3>Welcome</h3>
<p>Welcome to the second edition of the CakePHP weekly summaries.<br />
Its quite embarrassing that it had to take so long time to get the second editon out. Too long time has passed and the amount of things that has happend during that period is waaay too big to be covered here.<br />
Therefor I present this half-done 2nd edition of the weekly summaries, with a promise that every week from now on I will give you the latest and greatest from the CakePHP world.<br />
So with no further ado, please enjoy this old and probably rather outdated edition of the <del>weekly</del>monthly summaries. <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  See you at the 3rd edition soon <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Trac changes</h3>
<ul>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6321">Changeset #6321</a> (phpnut) Fixes <a title="Some non-executable files in source tree have executable permissions (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3817">Ticket #3817</a>, Some non-executable files in source tree have executable permissions
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6322">Changeset #6322</a> (phpnut) Updating controller tests created with the console. Added associated fixtures to model tests
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6323">Changeset #6323</a></strong> (gwoo) Updating Cache to apply prefix for every key, closes <a title="Namespace Support for Cache (memcached) (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3821">Ticket #3821</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6324">Changeset #6324</a> (phpnut) Correcting links generated to additional app tests
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6325">Changeset #6325</a> (phpnut) Adding support for test fixture generation when creating models, this will eventually be moved to a task. Currently the $records are hard coded to create field type specific data, this will eventually be changed to create random data based on the field type. Refactored tests that are created for models, 3 working tests are not created when generating tests for the model. Added notice output to terminal when creating a project, the CAKE_CORE_INCLUDE_PATH is automatically altered and may need to be changed when moving to a production environment. &#8221;
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6326">Changeset #6326</a> (phpnut) Fixes svn file property line
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6327">Changeset #6327</a> (phpnut) Removing unneeded &#8216; : &#8216;
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6328">Changeset #6328</a> (phpnut) Removing unneeded &#8216; : &#8216;
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6329">Changeset #6329</a></strong> (nate) Fixing reading and writing in Configure class for references 3 levels deep, fixes <a title="Configure doesnt read/write keys with more than two levels (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3845">Ticket #3845</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6330">Changeset #6330</a> (nate) Removing un-needed method from TimeHelper? test
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6331">Changeset #6331</a> (phpnut) Removing var $useTable; from generated model when tables follow conventions Fixed issue with model tests and fixtures not being created properly when Model name does not match table name
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6332">Changeset #6332</a> (phpnut) Updating controller tests created with the console. Added associated fixtures to model tests
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6333">Changeset #6333</a></strong> (phpnut) Fixes <a title="Deprecated loadView() call in email component when using theme (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3849">Ticket #3849</a>, Deprecated loadView() call in email component when using theme
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6334">Changeset #6334</a> (gwoo) updating HttpSocket? with auth, closes <a title="HttpSocket auth doesn't work (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3838">Ticket #3838</a> removing type casting, fixes <a title="HttpSocket may improberly cast long numbers to ints, changing the value (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3827">Ticket #3827</a> adding socket.group to tests
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6335">Changeset #6335</a> (gwoo) updating component, removing use of Router not needed anymore, fixes <a title="Fatal error: Class 'Router' not found (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3858">Ticket #3858</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6336">Changeset #6336</a> (nate) Adding non-null association key fix in Model, and updating Model::isUnique() to account for current record, fixes [ticket fixed 38599, closes [ticket fixed #2032]
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6337">Changeset #6337</a></strong> (nate) Fixing return value in Model::saveAll(), fixes <a title="saveAll() Reporting Incorrect Result (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3852">Ticket #3852</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6338">Changeset #6338</a> (phpnut) Fixes <a title="Scaffolding and bake script has problems with tables that has underscore in it's name. (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3829">Ticket #3829</a>, Scaffolding and bake script has problems with tables that has underscore in it&#8217;s name
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6339">Changeset #6339</a> (phpnut) Fixes <a title="custom scaffolding file lookup paths inconsistent (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3798">Ticket #3798</a>, custom scaffolding file lookup paths inconsistent
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6340">Changeset #6340</a> (phpnut) Fixes <a title="set_time_limit(0) has no effect because of ini_set('max_execution_time', 60 * 5); (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3862">Ticket #3862</a>, set_time_limit(0) has no effect because of ini_set(&#8216;max_execution_time&#8217;, 60 * 5); changed max_execution_time , 0. Since php 4.3 this is the default anyway
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6341">Changeset #6341</a></strong> (phpnut) Fixes <a title="$_SESSION not found (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3811">Ticket #3811</a>, $_SESSION not found Fixes [ticked fixed 3823], Session not restarted after instantiating new SessionComponent? Fixes #3850, Configuration Session.start and SessionComponent::__active aren&#8217;t handle correctly
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6342">Changeset #6342</a></strong> (phpnut) Fixes <a title="Acl component fails to check() if a permission is denied in action (*) (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3851">Ticket #3851</a>, Acl component fails to check() if a permission is denied in action (*)
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6343">Changeset #6343</a> (phpnut) Adding test cases from [ticked closed 3810]
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6344">Changeset #6344</a> (phpnut) Reverting [] and [] this commit broke the working implementation. Closes <a title="__doThread function of model_php5/model_php4 is broken (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3810">Ticket #3810</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6345">Changeset #6345</a> (phpnut) Fixes <a title="Scaffolding is generating an id field with an empty value for auto_increment primary key (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3854">Ticket #3854</a>, Scaffolding is generating an id field with an empty value for auto_increment primary key
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6346">Changeset #6346</a> (phpnut) Fixing bug with scaffold and valid Session id check
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6347">Changeset #6347</a> (phpnut) Fixing bug with scaffold and valid Session id check in 1.1.x.x
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6348">Changeset #6348</a> (gwoo) updating View error handling for extensions, fixes <a title="Can't change extension of layout file (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3795">Ticket #3795</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6349">Changeset #6349</a> (nate) Correcting parameter declaration in API shell
</li>
<li><strong><a target="blank" href="http://trac.cakephp.org/changeset/6350">Changeset #6350</a></strong> (nate) Fixing database drivers for UPDATE/DELETE changes, updating drivers to comply with model tests, most passing. Fixes <a title="DB support for Aliases in genereted UPDATE SQL (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3794">Ticket #3794</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6351">Changeset #6351</a> (nate) Whitespace fixes
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6352">Changeset #6352</a> (gwoo) adding connection param to schema shell
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6353">Changeset #6353</a> (nate) Enabling alternate titles for PaginatorHelper::sort() links based on sort direction, closes <a title="Introduce different titles for Paginator::sort() depending on direction (closed and fixed)" style="color: green" target="blank" href="https://trac.cakephp.org/ticket/3865">Ticket #3865</a>
</li>
<li><a target="blank" href="http://trac.cakephp.org/changeset/6354">Changeset #6354</a> (nate) Removing MySQL-specific schema code from core, improving support for PostgreSQL sequences, most tests passing
</li>
</ul>
<h3>Google group topics</h3>
<h4>Why doesn&#39;t Find* return a group of model objects?</h4>
<p>This topic has been discussed <strong>many</strong> times before, but Deane felt that it was required to ask yet again: &#8220;<a title="Google group: Why doesn&#39;t Find* return a group of model objects?" target="blank" href="http://groups.google.com/group/cake-php/browse_thread/thread/77794ca01fa52f9f">Why doesn&#39;t Find* return a group of model objects?</a>&#8220;. He wanted to be able to work with his models in the view (!BAD DESIGN!), and was confused why he only got an array back from the find* methods. Gwoo replied, and I quote: &#8220;<strong>Speed, simplicity, clarity</strong>&#8221; and pointed out that Cake provide view helpers to work with the arrays in almost any way you can imagine, and that the models provide callback functions (afterFind, afterSave, beforeFind, beforeFind) to format your data.<br />
Deane thanked gwoo for the reply, but &#8220;We couldn&#8217;t disagree more strenuously, and we think you&#8217;re wrong beyond belief in your reasoning, but we appreciate the response&#8221;&#8230;. didnt like gwoo&#8217;s reply at all.<br />
Gwoo replied in a calmly matter that &#8220;Everyone is entitled to their opinion and their choice of frameworks.&#8221;<br />
rtconner joined the discussion, offering a solution based on some old code by gwoo that would enable the <a href="http://bin.cakephp.org/saved/24245">models to return objects</a> (StdClass, not models classes)instead of arrays.<br />
Nick also joined the thread, backing up Deaen&#8217;s point of view (Cake is wrong, symfony lover is right) that its proper OO to use objects instead of arrays for the view data, but also reasoned that cake does indeed have the needed hooks and concepts to achieve Deane&#8217;s initial idea with a minimal effort. He explained that in a project he had created with CakePHP was that relationships (belongsTo, hasMany ect.) get more complicated with the OO styled approach, since the queries often fetched much more data than was really needed in the view. The combination of the controller didnt know wich fields the view required and the complex relation ships was in his opinion, not ideal at all. Their work a round was to create a &#8220;LazyData&#8221; class to handle it.<br />
Robby Anderson dropped in his 2 cents, and agreed that the cake was isnt 100% pure OO, but that the concept of &#8220;having the view incapable of performing any meaningful business logic&#8221; is bad, and will sooner or later lead to an unmanagelbe code base.<br />
Deane, the creater of the thread, posted a public apoligy to gwoo, explaining that he was fustrated at the time when he posted his previous post.</p>
<p>So, the summary must be that while some people dont like the design decission that CakePHP models return arrays instead of objects, others agree that its the right way to encapsulate the buisness logic in a correct Model View Control manner, and if you want to break theese convensions, its rather easy to do with minimal effort.</p>
<h4>Passing Data To A Form</h4>
<p>Travis asked how you are <a title="Google group: Passing Data To A Form" target="blank" href="http://groups.google.com/group/cake-php/browse_thread/thread/92d9341a3bf14699">Passing Data To A Form</a>. A bit unexpted (or perhaps expected given the flood of duplicate / newbie questions hitting the groups daily) nobody answered his question. The answer is pretty simple, and covered in any tutorial aviable on cakephp website AND in the documenation / manual.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$employeeID</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span> 
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Employee<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>findAllById<span style="color: #009900;">&#40;</span><span style="color: #000088;">$employeeID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>The Show Is Back!</h4>
<p>Jeff Loiselle aka phishy announced that <a target="_blank" href="http://live.cakephp.org">the show is back</a>. No replies, no thing, its sad&#8230; the show rocks !</p>
<h4>I18n in 1.2 model validation message</h4>
<p>Athies asked how does <a title="Google group: i18n in 1.2 model validation message" target="blank" href="http://groups.google.com/group/cake-php/browse_thread/thread/6ac5b6520c7e39df">i18n in 1.2 model validation message</a> work. His iniital attemp was to use the i18n method &#8216;__()&#8217; in the model $validate array, but he was getting syntax errors when doing that.<br />
Since PHP does not support useage of functions in instance delclarations its not possible to use i18n directly in the validate array.<br />
Francky06l pointed at his solution in another google post <a title="Google group: i18n: static language references with __(&quot;My lang key&quot;, true) in models and controllers" target="blank" href="http://groups.google.com/group/cake-php/browse_thread/thread/fa32c81acc043eef">i18n: static language references with __(&quot;My lang key&quot;, true) in models and controllers</a>, and while the solution will work, its far from ideal when working with i18n.<br />
A CakePHP google group regular, Dr. Tarique Sani, pointed out that the correct way to handle i18n validation messages was in the view, not at the model level. Amit Badkas backed up Tarique up and provided a simple example on how to do it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">echo</span> 
<span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>input<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
    <span style="color: #0000ff;">'alphanumeric'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Username must contain alpha-numeric characters'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'between'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Username must be between 8 to 20 characters'</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;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Francky06l seemed to know that, his consern was the if he multiple views where the validation errors should show, it would be convenient to do it at model level.<br />
Robby Anderson wasnt sure why you just couldnt do both, create the validation errors in the model, and wrap them in __() in the view.</p>
<p>And sure, that will work &#8211; but &#8211; you will loose some cake magic with that. The console application</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">cake i18n <span style="color: #990000;">extract</span></pre></div></div>

<p>will not add the i18n messages to the pot file automagic. Also, the i18n extract command will not even search your models for any i18n magic. It will only look in controllers and views. You can choose to call this a limit or a feature, but thats how cakephp has decided to do it, to enforce their paradime on how an application should be build and structured.</p>
<h4>FormHelper Labels</h4>
<p>Travis asked how it was possible to disable the automagic label in the FormHelper. Robby Anderson provided the correct solution for this issue, use &#8216;label&#8217; =&gt; <strong>false</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>input<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Employee.name'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</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>?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<h4>Using model objects in the controllers</h4>
<p><a href="#Why_doesn.26.2339.3Bt_Find.2A_return_a_group_of_model_objects.3F">Deane from earlier</a> posted another question on <a title="Google group: Using model objects in the controllers" target="blank" href="http://groups.google.com/group/cake-php/browse_thread/thread/3d03fd90d7fabaea">Using model objects in the controllers</a>. I dont really want to dwell much on this post, since its really attemp to take CakePHP in another direction than its supposed to. Deane clearly shows a lack of insight on how cakephp is supposed to work, and failed to provide any usefull examples that could show the group what he wanted to do.</p>

	Tags: <a href="http://www.cakephp.nu/t/cakephp" title="Cakephp" rel="tag">Cakephp</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/weekly-summaries" title="weekly summaries" rel="tag">weekly summaries</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/cakephp-weekly-summaries-issue-2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CakePHP Weekly Summaries Issue #1.5</title>
		<link>http://www.cakephp.nu/cakephp-weekly-summaries-issue-15</link>
		<comments>http://www.cakephp.nu/cakephp-weekly-summaries-issue-15#comments</comments>
		<pubDate>Mon, 21 Jan 2008 20:22:34 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[weekly summaries]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/cakephp-weekly-summaries-issue-15</guid>
		<description><![CDATA[
Hello, just wanted to post a quick apoligy Sorry that I havent created the weekly summaries for almost 1.5 week now. The reason is that I have begun on a new job, and its consuming quick alot of time and energy Lot of new systems to learn (They dont use Cake&#8230;. yet, booooh!) I have [...]
]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
just wanted to post a quick apoligy <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Sorry that I havent created the weekly summaries for almost 1.5 week now. The reason is that I have begun on a new job, and its consuming quick alot of time and energy <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Lot of new systems to learn (They dont use Cake&#8230;. yet, booooh!) </p>
<p>I have the second edition 80% done, just need to clean it up and proof read it a few times <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Should be done before this weekend</p>

	Tags: <a href="http://www.cakephp.nu/t/cakephp" title="Cakephp" rel="tag">Cakephp</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/weekly-summaries" title="weekly summaries" rel="tag">weekly summaries</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/cakephp-weekly-summaries-issue-15/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CounterCache in CakePHP 1.2 beta</title>
		<link>http://www.cakephp.nu/countercache-cakephp-12-beta</link>
		<comments>http://www.cakephp.nu/countercache-cakephp-12-beta#comments</comments>
		<pubDate>Fri, 04 Jan 2008 23:32:54 +0000</pubDate>
		<dc:creator>Christian Winther</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[counter cache]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/countercache-cakephp-12-beta</guid>
		<description><![CDATA[
Update 05.01.2008 At the moment the counterCache code is only executed on CREATE, not on UPDATE &#8211; a patch is under way Hello, Just a little turtorial to demonstrate the new model counterCache feature. CounterCache is a very fancy little addition to our beloved CakePHP framework. Simply put, all it does is make sure that [...]
]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong><br />
<em>05.01.2008</em> At the moment the counterCache code is only executed on CREATE, not on UPDATE &#8211; a patch is under way</p>
<p>Hello,</p>
<p>Just a little turtorial to demonstrate the new model counterCache feature.</p>
<p>CounterCache is a very fancy little addition to our beloved CakePHP framework.<br />
Simply put, all it does is make sure that your belongsTo associations always have an updated field with the count of elements belonging to the parent.</p>
<p>Lets use this simple example, just two models and controllers:</p>
<ul>
<li>Posts (posts_controller) (hasMany PostComment)
</li>
<li>PostComments (post_comments_controller) (belongsTo Post)
</li>
</ul>
<h3>SQL</h3>

<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
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- our posts </span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`posts`</span> <span style="color: #66cc66;">&#40;</span> 
  <span style="color: #ff0000;">`id`</span> int<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;">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;">`post_comment_count`</span> int<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;">`title`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</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: #66cc66;">,</span> 
  <span style="color: #ff0000;">`body`</span> text <span style="color: #993333; font-weight: bold;">NOT</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 ROW_FORMAT<span style="color: #66cc66;">=</span>DYNAMIC;             
&nbsp;
<span style="color: #808080; font-style: italic;">-- comments to our post </span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`post_comments`</span> <span style="color: #66cc66;">&#40;</span> 
  <span style="color: #ff0000;">`id`</span> int<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;">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;">`post_id`</span> int<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;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">`is_active`</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;">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;">DEFAULT</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">`name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</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: #66cc66;">,</span> 
  <span style="color: #ff0000;">`body`</span> text <span style="color: #993333; font-weight: bold;">NOT</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;">`post_id`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`post_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 ROW_FORMAT<span style="color: #66cc66;">=</span>DYNAMIC;</pre></td></tr></table></div>

<p>To keep things simple, we are just going to use scaffolding in controllers.</p>
<h3>Controllers</h3>
<h4>Posts controller</h4>
<p>Put in APP/controllers/posts_controller.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #666666; font-style: italic;">// Posts controller </span>
<span style="color: #000000; font-weight: bold;">class</span> PostsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$scaffold</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>PostComments controller</h4>
<p>Put in APP/controllers/post_comments_controller.php</p>
<pre></pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #666666; font-style: italic;">// Post comments controller </span>
<span style="color: #000000; font-weight: bold;">class</span> PostCommentsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$scaffold</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Models</h3>
<h4>Post model</h4>
<p>Put in APP/models/post.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</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;">'PostComment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>PostComment model</h4>
<p>Put in APP/models/post_comment.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #000000; font-weight: bold;">class</span> PostComment <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</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;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'counterCache'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</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> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The interesting thing is the above <strong>PostComment</strong> model. A you can see, a new options key is added, <strong>counterCache</strong> and is set to <u>(bool) true</u>. This informs cake that it should use counterCache on the class (Post) it belongs to.<br />
This is three possible variables to assign <strong>counterCache</strong></p>
<ul>
<li><strong>(bool) true</strong> means enabled, and that cake should auto-generate the count field automagic
</li>
<li><strong>(string) fieldname</strong> tells cake to use your custom field in Post (posts) model and table.
</li>
<li><strong>any value that is considered &#8216;empty&#8217;</strong>disable the feature (this is default, NULL)
</li>
</ul>
<p>Its important to understand, that the field we specify here, is a field in the REMOTE model / table, not in the local table, so in this case, the field name is in <strong>posts</strong> table.!</p>
<p>As said earlier, cake will automagic generate the remote field name if you only provide a boolean true value, in this case the field will be named <strong>Inflector::underscore($this-&gt;alias) . &#8216;_count&#8217;</strong> &#8211; meaning the alias of the <strong>LOCAL</strong> model (PostComment) and a suffix &#8216;_count&#8217;. All is that is converted to a lowercase, underscored value. When these rules are applied to our example above, the remote field in posts will be named <strong>post_comment_count</strong> (line 4 in SQL section)</p>
<p>With the code above, you have a very basic scaffolding setup running with couterCache enabled. Very simple stuff <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  As always when its from the CakePHP team.</p>
<h3>Using counterCache scope</h3>
<p>As you might have noticed in the SQL table above, the post_comments table have a field called <strong>is_active</strong> (SQL line 14). This is a sample on how you could moderate your comments. Lets change a bit of code in our models to make this work.</p>
<p>Put in APP/models/post.php (Updated)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #666666; font-style: italic;">// Updated Post model </span>
<span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</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;">'PostComment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Notice that I have added a <strong>conditions</strong> array to the <strong>hasMany</strong> relation to <strong>PostComment</strong>.<br />
This will tell cake to only fetch comments from PostComment where is_active is 1 (aka. is active).</p>
<p>Put in APP/models/post_comment.php (Updated)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php 
<span style="color: #000000; font-weight: bold;">class</span> PostComment <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</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;">'Post'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">'counterCache'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">'counterScope'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_active'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Notice that I have added another field to the <strong>Post</strong> relation called <strong>counterScope</strong>, this is the conditions that cake uses in the <strong>find(&#8216;count&#8217;)</strong>query it creates to find the amount of comments to the Post. By adding this simple array, our counterCache now only count active comments <img src='http://www.cakephp.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Easy done</p>

	Tags: <a href="http://www.cakephp.nu/t/cakephp" title="Cakephp" rel="tag">Cakephp</a>, <a href="http://www.cakephp.nu/t/counter-cache" title="counter cache" rel="tag">counter cache</a>, <a href="http://www.cakephp.nu/t/english" title="english" rel="tag">english</a>, <a href="http://www.cakephp.nu/t/tutorials" title="tutorials" rel="tag">tutorials</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/countercache-cakephp-12-beta/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc

Served from: www.cakephp.nu @ 2012-02-05 16:08:34 -->
