<?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>Guy Rutenberg &#187; CakePHP</title>
	<atom:link href="http://www.guyrutenberg.com/tag/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Sat, 14 Jan 2012 11:30:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Configuring Lighttpd for CakePHP</title>
		<link>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/</link>
		<comments>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 21:38:09 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Lighttpd]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=252</guid>
		<description><![CDATA[I tried a few days ago to install a CakePHP project of mine on a lighttpd web-server. As expected, it&#8217;s clean URLs didn&#8217;t work, so I set out to find a solution. One possible solution is the one oulined in the CakePHP manual. The solution uses the mod_magnet module (which basically runs a Lua script [...]]]></description>
			<content:encoded><![CDATA[<p>I tried a few days ago to install a <a href="http://www.cakephp.org">CakePHP</a> project of mine on a <a href="http://www.lighttpd.net">lighttpd</a> web-server. As expected, it&#8217;s clean URLs didn&#8217;t work, so I set out to find a solution.</p>
<p>One possible solution is the <a href="http://book.cakephp.org/view/782/Lighttpd-and-mod_magnet">one</a> oulined in the CakePHP manual. The solution uses the <code>mod_magnet</code> module (which basically runs a Lua script to do the rewriting), and I found it an overkill. I was looking for a simple solution based only on <code>mod_rewrite</code>, something like the <a href="/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/">solution for WordPress</a>.<br />
<span id="more-252"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$HTTP[&quot;host&quot;] =~ &quot;^(www\.)?example.com&quot; {
        server.document-root = &quot;/home/guy/example.com/app/webroot/&quot;
        url.rewrite = (
                &quot;(css|files|img|js)/(.*)&quot; =&gt; &quot;/$1/$2&quot;,
                &quot;^([^\?]*)(\?(.+))?$&quot; =&gt; &quot;/index.php?url=$1&amp;$3&quot;,
        )
}</pre></div></div>

<p>I will go line by line over the solution. The first line defines a vhost for the site. This is a simple vhost that uses conditional configurations. The second line sets the server&#8217;s document root to my app&#8217;s webroot directory (you&#8217;ll need to change the path accordingly). The next section is the URL rewriting which is the most important part. The first line of the rewriting rules takes care of the static files you serve from the document root, e.g. CSS, JavaScript, image etc. You can add to the begining of the rule (the <code>css|files|img|js</code> any other directory you would like to sever static files from). The next line takes care of Cake&#8217;s clean URLs. It&#8217;s important to capture any query string explicitly, if exists, and pass it in appropriate way so GET variables will be passed correctly.</p>
<p>I hope other CakePHP users who want to develop their apps on lighttpd will find this &#8220;lightweight&#8221; solution helpful. Don&#8217;t hesitate to ask question and post your comments about this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Trailing Whitespace Causes a Session to be Destroyed in CakePHP</title>
		<link>http://www.guyrutenberg.com/2008/03/08/trailing-whitespace-causes-a-session-to-be-destroyed-in-cakephp/</link>
		<comments>http://www.guyrutenberg.com/2008/03/08/trailing-whitespace-causes-a-session-to-be-destroyed-in-cakephp/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 22:36:31 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2008/03/08/trailing-whitespace-causes-a-session-to-be-destroyed-in-cakephp/</guid>
		<description><![CDATA[While working on a new project using CakePHP, I&#8217;ve came across a weird problem. In one of the controllers the the session always came out as invalid, as $this-&#62;Session-&#62;valid&#40;&#41; always returned false. I tried debugging this weird stuff, and it looked like all the session variables are unset. Using $this-&#62;Session-&#62;error&#40;&#41; to get the last error [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a new project using <a href="http://www.cakephp.org">CakePHP</a>, I&#8217;ve came across a weird problem. In one of the controllers the the session always came out as invalid, as</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>always returned false. I tried debugging this weird stuff, and it looked like all the session variables are unset. Using</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>to get the last error returned &#8220;Config doesn&#8217;t exist&#8221;. After further debugging &#8220;Config&#8221; turned out to be an internal array that is saved by CakePHP to the session and holds various internal data (some of it is used for validation like user-agent hash). I kept printing more and more debugging data as well as looking at CakePHP&#8217;s trac system.</p>
<p>I found an interesting bug (<a href="https://trac.cakephp.org/ticket/4217">ticket #4217</a>) and it looked very promising, as it almost fully described my problem. Unfortunately, the solution offered didn&#8217;t seem to work for me. But it inspired me to try and start the session manually using <code>session_start()</code> instead of using Cake&#8217;s startup and activate methods of the Session Component. </p>
<p>I found out that the <code>session_id()</code> returned empty string. Luckily calling <code>session_start()</code> directly from the controller, gave me a lead. The session seemed to work well but a nasty error about headers already been sent showed up.</p>
<p>I little more investigation lead up that I had a trailing newline after my closing PHP tag in that controller file. Deleting this trailing whitespace completely solved the problem. No need anymore to manually start the session. It&#8217;s pretty annoying that such a small thing like trailing new line can cause such seemingly unrelated problems in CakePHP&#8217;s session handling.</p>
<p>Maybe CakePHP should add a little debug notice when the session doesn&#8217;t start because header were already sent. This can be done by modifying the <code>else</code> statement in the <code>__startSession()</code> method in <code>cake/lib/session.php</code> (line 557 in version 1.2.0.6311). I wonder what the reason they had not to inform the developer when such event happens, as I don&#8217;t see why someone will deliberately try to start the session after sending the headers, I think it only happens by mistake (at least most of the time).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/03/08/trailing-whitespace-causes-a-session-to-be-destroyed-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.747 seconds -->

