<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Yet another blog about PHP, HTML and CSS</title>
	
	<link>http://blog.pepa.info</link>
	<description>Petr 'PePa' Pavel</description>
	<pubDate>Wed, 08 Jul 2009 09:53:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/YetAnotherBlogAboutPhpHtmlAndCss" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Alternative icon for Eclipse IDE</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/2LbfGl9sI2k/</link>
		<comments>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 09:52:01 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=136</guid>
		<description><![CDATA[Each year we have the pleasure of switching to a new version of Eclipse. And by pleasure I mean both shades of the word. Cool new features and boring migration. I usually fight my laziness for quite some time and migrate my projects gradually. Thanks folks for keeping Eclipse isolated so that I can run [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.pepa.info/wp-content/feature.gif" alt="" title="Alternative Eclipse icon" width="32" height="32" class="alignleft size-full wp-image-140" />Each year we have the pleasure of switching to a new version of Eclipse. And by pleasure I mean both shades of the word. Cool new features and boring migration. I usually fight my laziness for quite some time and migrate my projects gradually. Thanks folks for keeping Eclipse isolated so that I can run both versions simultaneously. I&#8217;m getting to my point now: I needed a new icon that would distinct the new version from the old one.<br />
<span id="more-136"></span><br />
After a proper googling I came to a conclusion that there simply isn&#8217;t one I could just download and use (ico for Windows). So I searched through the Galileo directory and found a nice gif icon:<br />
<code><br />
C:\Program Files\Eclipse 3.5 PDT\configuration\org.eclipse.osgi\bundles\162\1\.cp\feature.gif<br />
</code></p>
<p>Then I googled for an online ico creator and found <a href="http://iconverticons.com/">iConvert</a> that can not only create Windows icons but also Mac and Linux icons.<br />
Click, click and I was finally able to link my shortcut to a new icon. Perfect!</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/2LbfGl9sI2k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/</feedburner:origLink></item>
		<item>
		<title>Duplicating sets of radio buttons with jQuery</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/3RgxainjTDc/</link>
		<comments>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 18:02:54 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=129</guid>
		<description><![CDATA[We all love the &#8220;add more&#8221; links for adding more form items to forms. More pictures to upload, more categories to add. You just name them with empty square brackets and then clone them. 



&#160;


&#60;input type=&#34;file&#34; name=&#34;file[]&#34; value=&#34;&#34;&#62;



&#60;a href=&#34;&#34; id=&#34;addMoreUploads&#34;&#62;add more&#60;/a&#62;



&#160;



But what if you need to clone sets of radio buttons? You end up with [...]]]></description>
			<content:encoded><![CDATA[<p>We all love the &#8220;add more&#8221; links for adding more form items to forms. More pictures to upload, more categories to add. You just name them with empty square brackets and then clone them. </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;file&quot; name=&quot;file[]&quot; value=&quot;&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;a href=&quot;&quot; id=&quot;addMoreUploads&quot;&gt;add more&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>But what if you need to clone sets of radio buttons? You end up with a single group of radio buttons - not with a group of radio button groups.<br />
<span id="more-129"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;moreContainer&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;cloneThis set&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;1&quot;&gt; one
</div>
</li>
<li class="li2">
<div class="de2">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;2&quot;&gt; two
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;3&quot;&gt; three
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;a href=&quot;&quot; class=&quot;addMore&quot;&gt;add more&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>If you clone the whole cloneThis group you&#8217;ll get a group of six radio buttons but you&#8217;ll be able to choose just one.</p>
<p>Unfortunately, you have to give up the empty square brackets and start numbering them (name=&#8221;options[0]&#8220;). In the cloning function then you replace the cloned number with an ever increasing counter value.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;.addMore&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw2">var</span> parentContainer = $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">parents</span><span class="br0">&#40;</span><span class="st0">&quot;.moreContainer&quot;</span><span class="br0">&#41;</span>.<span class="me1">eq</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// the closest container (you can have nested containers too)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> cloneSource = parentContainer.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;.cloneThis&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> clonedSet = cloneSource.<span class="me1">clone</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="co1">// duplicate the set of form items</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> itemsCount = parentContainer.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;.set&quot;</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// count # of already duplicated sets</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="coMULTI">/*</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp;* Increment index of each for item</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;* we can&#8217;t use [] because of radio buttons</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; clonedSet.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;input&quot;</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>index, element<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw1">this</span>.<span class="kw3">name</span>.<span class="me1">replace</span><span class="br0">&#40;</span><span class="re0">/\<span class="br0">&#91;</span><span class="nu0">0</span>\<span class="br0">&#93;</span>/</span>, <span class="st0">&quot;[&quot;</span>+itemsCount+<span class="st0">&quot;]&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// &nbsp; &nbsp;$(element).val(itemsCount); // this works as a debugger for type=&quot;text&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; clonedSet.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">&quot;cloneThis&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// remove class &#8216;cloneThis&#8217; to avoid duplicating it in the next round</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// &nbsp; &nbsp;clonedSet.find(&quot;input[name*='zoom'][value=3]&quot;).attr(&quot;checked&quot;, true); ;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// use this syntax to set a default value</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; cloneSource.<span class="me1">after</span><span class="br0">&#40;</span>clonedSet<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>This function is generic and works for any set of input fields (not textarea and select though). You can have many &#8220;add this&#8221; and &#8220;add that&#8221; on a single page and still use the same function. You just have to switch from using id to class for identifying the containers, links and cloning sources.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/3RgxainjTDc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/</feedburner:origLink></item>
		<item>
		<title>MySQL comparison catch: ‘abc’ = 00</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/03Xx2K11c-Q/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/#comments</comments>
		<pubDate>Mon, 25 May 2009 20:39:00 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Database]]></category>

		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=113</guid>
		<description><![CDATA[I was shocked to find a weakness in my authentication library today. It was possible to get around the password check if you knew the username. All you had to do was to enter 00 as the password. Or you just entered 00 as the username too and you got authenticated as the first user.

The [...]]]></description>
			<content:encoded><![CDATA[<p>I was shocked to find a weakness in my authentication library today. It was possible to get around the password check if you knew the username. All you had to do was to enter 00 as the password. Or you just entered 00 as the username too and you got authenticated as the first user.<br />
<span id="more-113"></span><br />
The bug was a combination of these three things:</p>
<ol>
<li>A password (or/and username) that doesn&#8217;t contain any numbers</li>
<li>MySQL type conversion in conditions - when comparing a VARCHAR column to an INTEGER value it converts VARCHAR to INTEGER, not the other way around.</li>
<li>My own database wrapper was trying to be smart and didn&#8217;t wrap numeric values with apostrophes</li>
</ol>
<p>Consider this template:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = %s<span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = %s<span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>and something along these PHP lines:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;username&#8217;</span><span class="br0">&#93;</span> &amp;&amp; <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;password&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// will catch 0 but not 00</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>mysqlValue<span class="br0">&#40;</span><span class="re0">$sqlTemplate</span>, <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;username&#8217;</span><span class="br0">&#93;</span>, <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;password&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;welcome&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;wrong password&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I won&#8217;t go into details about <code>mysqlValue()</code>. The important part is that it checks for special cases of NULL, true, false and is_numeric() and runs the rest through mysql_real_escape_string(). Then it inserts all parameters into the template using vprintf().</p>
<p>The problem is with is_numeric(). After being evaluated as a numeric value, &#8216;00&#8242; is entered into the query without apostrophes.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = <span class="st0">&#8216;my_username&#8217;</span><span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = <span class="nu0">00</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>And because any varchar that doesn&#8217;t contain a number compared to an integer is evaluated as true the result is a catastrophe.</p>
<p><code>'abc' = 00</code> is evaluated as true. <code>'abc1' = 00</code> would be false however, unfortunately only few users append a number to their password. If you use 00 for both the username and the password you get authenticated as the first user who didn&#8217;t do so.</p>
<p>Check out this <a href="http://bugs.mysql.com/bug.php?id=42241">false bug report</a> or the <a href="http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html">related documentation page</a>.</p>
<h2>Why you could want to pass numeric values without apostrophes</h2>
<p>I wonder myself :-) Here are some reasons I remembered:</p>
<ul>
<li>Using %d and %s in SQL templates provides a visual clue about what values can be expected there</li>
<li>Using apostrophes for integer comparison (1 = &#8216;1&#8242;) means unnecessary type conversion that takes time. A small amount of time but still.</li>
</ul>
<h2>So how to fix this mess?</h2>
<p>What do you think? Should I remove the is_numeric() test and replace all %d with %s in all SQL templates? Remember that <code>printf("%d", "'123'")</code> will return 0.<br />
Or should I keep the is_numeric() test and rewrite vulnerable queries to use for example CAST:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = CAST<span class="br0">&#40;</span>%s <span class="kw1">AS</span> CHAR<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = CAST<span class="br0">&#40;</span>%s <span class="kw1">AS</span> CHAR<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/03Xx2K11c-Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/</feedburner:origLink></item>
		<item>
		<title>Switching layout using a url parameter</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/R4WIFKNQDJw/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 22:57:35 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=99</guid>
		<description><![CDATA[I needed to open a static page in a pop-up window. For static pages we have a handy controller Pages but I wanted to use a different layout for each page and do it in a flexible way.

The magic of my solution is in three lines of code in AppController (app/app_controller.php). I simplify the code [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to open a static page in a pop-up window. For static pages we have a handy controller Pages but I wanted to use a different layout for each page and do it in a flexible way.<br />
<span id="more-99"></span><br />
The magic of my solution is in three lines of code in AppController (app/app_controller.php). I simplify the code for the sake of clarity:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> AppController <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">function</span> beforeFilter<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/empty"><span class="kw3">empty</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">passedArgs</span><span class="br0">&#91;</span><span class="st0">&#8216;layout&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">layout</span> = <span class="re0">$this</span>-&gt;<span class="me1">passedArgs</span><span class="br0">&#91;</span><span class="st0">&#8216;layout&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I created a file /app/views/layouts/popup.ctp that contains only:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$content_for_layout</span>; <span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>And I call the static page as:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http:<span class="co1">//test.com/pages/termsOfMembership/layout:popup</span></div>
</li>
</ol>
</div>
<p>Which is created using this call:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$html</span>-&gt;<span class="me1">link</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="st0">&#8216;Terms of Membership&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;Router::<span class="me2">url</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;termsOfMembership&#8217;</span>, <span class="st0">&#8216;layout&#8217;</span> =&gt; <span class="st0">&#8216;popup&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;default&#8217;</span> =&gt; <span class="kw2">false</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;onclick&#8217;</span> =&gt; <span class="st0">&quot;window.open(this.href);&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#41;</span>,</div>
</li>
</ol>
</div>
<p>With this setting in my /app/config/routes.php:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">Router::<span class="me2">connect</span><span class="br0">&#40;</span><span class="st0">&#8216;/pages/*&#8217;</span>, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;display&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That Router setting is redundant if you use urls that look like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http:<span class="co1">//test.com/pages/display/termsOfMembership/layout:popup</span></div>
</li>
</ol>
</div>
<p>Then you also have to use a different call to the Router::url():</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;display&#8217;</span>, <span class="st0">&#8216;termsOfMembership&#8217;</span>, <span class="st0">&#8216;layout&#8217;</span> =&gt; <span class="st0">&#8216;popup&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/R4WIFKNQDJw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/</feedburner:origLink></item>
		<item>
		<title>Dealing with different configuration for development and production box</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/RSte_3x-bA8/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 00:16:42 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=94</guid>
		<description><![CDATA[All right, this isn&#8217;t exactly a rocket science, it&#8217;s just something I use and find very handy.
We all develop (and test) on one computer and deploy to a different computer to make the changes live. Having to run the application in two different environments brings a challenge of using different configuration based on where the [...]]]></description>
			<content:encoded><![CDATA[<p>All right, this isn&#8217;t exactly a rocket science, it&#8217;s just something I use and find very handy.</p>
<p>We all develop (and test) on one computer and deploy to a different computer to make the changes live. Having to run the application in two different environments brings a challenge of using different configuration based on where the application runs.<br />
<span id="more-94"></span></p>
<h3>Multiple configuration files</h3>
<p>I started by having two configuration files, one for my dev box and another for the production server. They were named the same and I had one on my dev box and one on the server. Each deployment though, meant that I had to be careful not to overwrite the server file with my local copy. That ruled out using a simple synchronization script like lftp or <a title="feature Keep Remote Directory Up To Date" href="http://winscp.net/eng/docs/task_keep_up_to_date" target="_blank">WinScp</a>.</p>
<p>The simplest solution is to name the configuration files differently and upload them both to both servers. All right, even simpler is to have a single configuration php file and define different values using if/else but that can quickly get out of hands as the number of variables grows.</p>
<p>If you need to upload to more production servers (more than one customer) you need to use some more sophisticated deployment script (Ant?).</p>
<p>Let&#8217;s return to the simple solution for now. You need to find a piece of information that can be used as a computer identifier and use it to choose the right set of configuration data.</p>
<h3>$_SERVER['SERVER_NAME'] &amp; $_SERVER['SERVER_ADDR']</h3>
<p>You can use these two for most situations. I develop on my workstation and I have set up domain name based web hosts (C:\xampp\apache\conf\extra\httpd-vhosts.conf) using fake domains (C:\WINDOWS\system32\drivers\etc\hosts).</p>
<p>Using $_SERVER['SERVER_NAME'] works when you know it up front but sometimes your client is going to choose it just before launching the site. Or he decides to change it later on. Not a big deal but I don&#8217;t like chaos.</p>
<p>$_SERVER['SERVER_ADDR'] is also fine but don&#8217;t forget to change it when your production server&#8217;s ip address changes. Not an issue if you use just two computers with 127.0.0.1 and &#8220;else&#8221;.</p>
<h3>Running scripts locally</h3>
<p>Sometimes you need to run a script locally as an extra level of security. Say you run a cron job and you don&#8217;t want public to mess with it by running it off schedule. So you run it as http://localhost/tadada.php and check for SERVER_NAME/ADDR to make sure it was indeed run that way. But then your cannot use it for picking the right configuration set.</p>
<h3>getenv(&#8221;COMPUTERNAME&#8221;) to the rescue</h3>
<p>This value is unlikely to change during the lifetime of your application and doesn&#8217;t change based on the way you run it. The drawback is that not all servers define this variable so you may have to seek a different computer identificator.</p>
<p>What is your way of dealing with configuration sets?</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/RSte_3x-bA8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/</feedburner:origLink></item>
		<item>
		<title>Populating a SELECT box with distinct values</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/gtRoDDl4MGk/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 22:13:24 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=90</guid>
		<description><![CDATA[Let&#8217;s say you log events into a database table Log. Attribute event holds event type and you want to filter the log listing just by that.
Here&#8217;s what you probably try at first:



&#160;


$this-&#62;set&#40;&#8216;events&#8217;, 


&#160; $this-&#62;Log-&#62;find&#40;&#8216;list&#8217;, 


&#160; &#160; array&#40;&#8216;fields&#8217; =&#62; &#8216;DISTINCT Log.event&#8217;, &#8216;Log.event&#8217;&#41;&#41;&#41;;


&#160;



It&#8217;s not gonna work and you will have to use find(&#8217;all&#8217;) and Set::combine() to get [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you log events into a database table Log. Attribute <i>event</i> holds event type and you want to filter the log listing just by that.</p>
<p>Here&#8217;s what you probably try at first:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$this</span>-&gt;<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&#8216;events&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Log</span>-&gt;<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;list&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;fields&#8217;</span> =&gt; <span class="st0">&#8216;DISTINCT Log.event&#8217;</span>, <span class="st0">&#8216;Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>It&#8217;s not gonna work and you will have to use find(&#8217;all&#8217;) and Set::combine() to get what you want:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$events</span> = <span class="re0">$this</span>-&gt;<span class="me1">Log</span>-&gt;<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;all&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;fields&#8217;</span> =&gt; <span class="st0">&#8216;DISTINCT Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$this</span>-&gt;<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&#8216;events&#8217;</span>, </div>
</li>
<li class="li2">
<div class="de2">&nbsp; Set::<span class="me2">combine</span><span class="br0">&#40;</span><span class="re0">$events</span>, <span class="st0">&#8216;{n}.Log.event&#8217;</span>, <span class="st0">&#8216;{n}.Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/gtRoDDl4MGk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/</feedburner:origLink></item>
		<item>
		<title>SQL functions or keywords in CakePHP conditions</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/I3-vJrLGXao/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 13:21:09 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=84</guid>
		<description><![CDATA[For those who missed the information, starting from CakePHP 1.2 it is no longer possible to use the magic tag -! in your condition to prevent your SQL function or keyword to be enclosed in quotes.
The recommended way now is to place it into the key or not make the array associative at all. It [...]]]></description>
			<content:encoded><![CDATA[<p>For those who missed the information, <a title="changeset details" href="https://trac.cakephp.org/changeset/5139" target="_blank">starting from CakePHP 1.2</a> it is no longer possible to use the magic tag -! in your condition to prevent your SQL function or keyword to be enclosed in quotes.</p>
<p>The recommended way now is to place it into the key or not make the array associative at all. It is no longer possible to put it into the value part of the definition.</p>
<p>So instead of:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;DATE_ADD(Payment.modified, INTERVAL 2 DAY) &gt;&#8217;</span> =&gt; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;CURRENT_DATE&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>you have to use:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;DATE_ADD(Payment.modified, INTERVAL 2 DAY) &gt; CURRENT_DATE&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/I3-vJrLGXao" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/</feedburner:origLink></item>
		<item>
		<title>What you can expect as $results in afterFind()</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/5xna33gjnO8/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 16:48:53 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=71</guid>
		<description><![CDATA[Function afterFind() can be called in various contexts with different types of $results. If you don&#8217;t handle them all properly the function will not work right (which you may not care in some cases) and you&#8217;ll end up with notice level errors.

Here are situations I stumbled upon, let me know if you have found some [...]]]></description>
			<content:encoded><![CDATA[<p>Function afterFind() can be called in various contexts with different types of $results. If you don&#8217;t handle them all properly the function will not work right (which you may not care in some cases) and you&#8217;ll end up with notice level errors.</p>
<p><span id="more-71"></span></p>
<p>Here are situations I stumbled upon, let me know if you have found some more:</p>
<ol>
<li>if your model contains a validation rule &#8216;isUnique&#8217; then afterFind() gets called from $model-&gt;invalidFields() with a result of SELECT COUNT():<br />
<strong> array(array(array(&#8217;count&#8217; =&gt; 1)))</strong></li>
<li>another results scheme is yielded by a model association (e.g. via belongsTo):<br />
<strong> array(&#8217;id&#8217; =&gt; 123, &#8216;first_name&#8217; =&gt; &#8216;Joe&#8217;&#8230;)</strong></li>
<li>and then there&#8217;s the regular $model-&gt;find() which gives<br />
<strong> array(<br />
0 =&gt; array(&#8217;ModelName&#8217; =&gt; array(&#8217;id&#8217; =&gt; 123, &#8230;)),<br />
1 =&gt; array(&#8217;ModelName&#8217; =&gt; array(&#8217;id&#8217; =&gt; 124, &#8230;))<br />
)</strong></li>
</ol>
<p>So what is the best way to work with this omnishaped variable?</p>
<p>First skip everything if there are no results:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$results</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Then check for case 2 (assuming your primary key is &#8216;id&#8217;):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="st0">&#8216;id&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>then for case 3:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">elseif</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="re0">$this</span>-&gt;<span class="me1">alias</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;id&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>and lastly you can check for the count result if you care:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">elseif</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_array"><span class="kw3">is_array</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> &amp;amp;&amp;amp; <a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;count&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/5xna33gjnO8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/</feedburner:origLink></item>
		<item>
		<title>Ganymede / PHPEclipse - not a good choice for debugging CakePHP</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/dPf7GKCrfOE/</link>
		<comments>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 19:57:40 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<category><![CDATA[Debugging]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=62</guid>
		<description><![CDATA[After hours of trying I finally conclude that CakePHP cannot be debugged in Eclipse 3.4.1 (Ganymede) and PHPEclipse 1.2.1.200810130444PRD (XDebug).
My webroot is set to app/webroot and Eclipse stops on a breakpoint only if it&#8217;s in app/webroot/index.php
Even after it stops there it won&#8217;t stop on a next breakpoint that is set in my controller.
The only working [...]]]></description>
			<content:encoded><![CDATA[<p>After hours of trying I finally conclude that CakePHP cannot be debugged in Eclipse 3.4.1 (Ganymede) and PHPEclipse 1.2.1.200810130444PRD (XDebug).</p>
<p>My webroot is set to app/webroot and Eclipse stops on a breakpoint only if it&#8217;s in app/webroot/index.php<br />
Even after it stops there it won&#8217;t stop on a next breakpoint that is set in my controller.</p>
<p>The only working solution I found is downgrading to Eclipse 3.3.2 (Europa) and PDT 1.0.3.v20080603. Fortunately both can run side by side so in theory, I can write new code in Ganymede and debug in Europa but that sucks. Programming is a constant debugging.</p>
<p>I could try to switch from XDebug to DBG. Maybe I will next time I have a day that I can waste.</p>
<h2>Update:</h2>
<p>New PDT 2.0.0.v20081030-1802 works with Ganymede/XDebug just fine. It also has features I have been missing like Mark Occurrences - one more reason for switching. It doesn&#8217;t have support for chm help files though (PHPEclipse does) and is generally slower than PHPEclipse.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/dPf7GKCrfOE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/</feedburner:origLink></item>
		<item>
		<title>Calculating time difference in months as a decimal number</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/Vwc568NKjOA/</link>
		<comments>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 20:54:21 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Design Techniques]]></category>

		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=44</guid>
		<description><![CDATA[There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number?
2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230;




function monthCount&#40;$start, $end&#41; &#123;


&#160; list&#40;$startYear, [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number?</p>
<p>2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230;</p>
<p><span id="more-44"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> monthCount<span class="br0">&#40;</span><span class="re0">$start</span>, <span class="re0">$end</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$startYear</span>, <span class="re0">$startMonth</span>, <span class="re0">$startDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$start</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$endYear</span>, <span class="re0">$endMonth</span>, <span class="re0">$endDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$end</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$startMonthCount</span> =</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span><span class="re0">$startYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// number of months since the beginning of our calendar</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$startMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// month number</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$startDay</span> - <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$start</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// day number divided by the number of days in that month</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$endMonthCount</span> = <span class="br0">&#40;</span><span class="re0">$endYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> + <span class="re0">$endMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$endDay</span> - <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$end</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$endMonthCount</span> - <span class="re0">$startMonthCount</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Note: end date is not inclusive.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/Vwc568NKjOA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/</feedburner:origLink></item>
	</channel>
</rss>
