<?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>Zé Ricardo&#039;s Blog</title>
	<atom:link href="http://www.josericardo.eti.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.josericardo.eti.br</link>
	<description>Yet another personal blog</description>
	<lastBuildDate>Tue, 31 Aug 2010 17:39:15 +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>About e-books and libraries</title>
		<link>http://www.josericardo.eti.br/2010/08/31/e-books-libraries/</link>
		<comments>http://www.josericardo.eti.br/2010/08/31/e-books-libraries/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 17:35:04 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[kindle]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=4690</guid>
		<description><![CDATA[This week I read some articles about declutering and I noticed how many books I have in my room. The fact is that I&#8217;m probably never going to read them again. What should I do with them? Some of them are old, from the time I was a freshman at the university. Nobody wants to [...]]]></description>
			<content:encoded><![CDATA[<p>This week I read some articles about declutering and I noticed how many books I have in my room. The fact is that I&#8217;m probably never going to read them again. What should I do with them? Some of them are old, from the time I was a freshman at the university. Nobody wants to read them anymore! What do I do with all this paper?</p>
<p>I was thinking about e-books and how they will help us to preserve the nature and space in our houses. And then I started to think about the future of libraries. How are the libraries of the future going to be? Do they still need to buy piles of books for the students? Then, I remembered that the newest kindle costs only US$ 139. <strong>How much do you think similar devices are going to cost in 2-5 years?</strong></p>
<p style="text-align: center;"><a href="http://www.josericardo.eti.br/wp-content/uploads/2010/08/kindle3.jpg"><img class="aligncenter size-medium wp-image-4691" style="border: 0pt none;" title="Kindle 3" src="http://www.josericardo.eti.br/wp-content/uploads/2010/08/kindle3-300x300.jpg" alt="" width="180" /></a></p>
<p><strong>How many Kindles do you think can be put in a cabinet?</strong> I don&#8217;t know, maybe 300? And now comes another fact, kindle books cost on average US$ 10 less than the printed versions. This way, if you buy fourteen books, you already have paid for your Kindle. <strong>How many books do you think a library buys per year?</strong></p>
<p>With all this in mind, I envisioned a library in which e-readers are lent instead of books. In this scenario, two things would be possible. In the worst case, students would have access to books via the campus wifi network. In the best case, all books from the library would be contained in the e-reader. Instead of getting one or two books, the whole library would be lent to students! Wouldn&#8217;t that be great?</p>
<p>The most amazing fact about all these thoughts I had yesterday is that they are perfectly possible, TODAY, even in a country like Brazil. Even here in my city (which is not that big), they have built a <strong>huge</strong> library. What if all that money was spent on e-readers and e-books? How much money and energy and trees would be saved?</p>
<p>This is surely the future I want to see coming true.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/08/31/e-books-libraries/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The First PHPMS Coding DOJO</title>
		<link>http://www.josericardo.eti.br/2010/08/14/phpms-coding-dojo/</link>
		<comments>http://www.josericardo.eti.br/2010/08/14/phpms-coding-dojo/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 22:49:04 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpms]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=3182</guid>
		<description><![CDATA[Today the local PHP Users Group (PHPMS) realized its first coding dojo. It was my second dojo (the first was yesterday ) and I think it&#8217;s a very interesting thing you should consider to do to improve your coding, communication skills and SPECIALLY your patience! It&#8217;s a great opportunity to meet new people and solve [...]]]></description>
			<content:encoded><![CDATA[<p>Today the local PHP Users Group (<a href="http://www.phpms.org">PHPMS</a>) realized its first <a href="http://codingdojo.org/">coding dojo</a>.</p>
<p><a href="http://www.josericardo.eti.br/wp-content/uploads/2010/08/DSC00857.jpg"><img src="http://www.josericardo.eti.br/wp-content/uploads/2010/08/DSC00857-300x225.jpg" alt="" title="The First PHPMS Coding Dojo" width="300" height="225" class="aligncenter size-medium wp-image-3189" /></a></p>
<p>It was my second dojo (the first was yesterday <img src='http://www.josericardo.eti.br/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and I think it&#8217;s a very interesting thing you should consider to do to improve your coding, communication skills and SPECIALLY your patience! It&#8217;s a great opportunity to meet new people and solve problems the RIGHT way.</p>
<p>Today, the goals were very modest and we decided to solve a very simple problem, the <a href="http://code.google.com/codejam/contest/dashboard?c=32004">Google Codejam&#8217;s Old Magician Problem</a>.</p>
<p><a href="http://www.josericardo.eti.br/wp-content/uploads/2010/08/DSC00859.jpg"><img src="http://www.josericardo.eti.br/wp-content/uploads/2010/08/DSC00859-300x225.jpg" alt="" title="The First PHPMS Coding Dojo" width="300" height="225" class="aligncenter size-medium wp-image-3191" /></a></p>
<p>You can see all the pictures I&#8217;ve taken during the event <a href="http://www.flickr.com/photos/josericardodasilva/sets/72157624600561213/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/08/14/phpms-coding-dojo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UI Fundamentals for Programmers by Ryan Singer</title>
		<link>http://www.josericardo.eti.br/2010/08/07/ui-fundamentals-programmers-ryan-singer/</link>
		<comments>http://www.josericardo.eti.br/2010/08/07/ui-fundamentals-programmers-ryan-singer/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 03:52:38 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=1063</guid>
		<description><![CDATA[Hi, I recently watched this presentation by Ryan Singer. I&#8217;m not a designer and I think the presentation was quite concise and straight-to-the-point. Really worth watching Ryan works for 37signals and I think it&#8217;s quite enough for his resumé, right?]]></description>
			<content:encoded><![CDATA[<p>Hi, I recently watched this presentation by Ryan Singer. I&#8217;m not a designer and I think the presentation was quite concise and straight-to-the-point. Really worth watching <img src='http://www.josericardo.eti.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ryan works for 37signals and I think it&#8217;s quite enough for his resumé, right?</p>
<p><object width="400" height="267"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6702766&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=b30000&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6702766&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=b30000&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="267"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/08/07/ui-fundamentals-programmers-ryan-singer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Digg Technical Talks &#8211; Rasmus Lerdorf</title>
		<link>http://www.josericardo.eti.br/2010/08/04/digg-technical-talks-rasmus-lerdorf/</link>
		<comments>http://www.josericardo.eti.br/2010/08/04/digg-technical-talks-rasmus-lerdorf/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 16:31:57 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=1057</guid>
		<description><![CDATA[Hi, did you know that Rasmus, the creator of PHP, has recently given a talk at the Digg office on PHP performance optimization? Very interesting, specially because he shows us which tools he uses to measure the performance of websites. The presentation is inspiring. It motivated me to learn more about the solutions I use [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, did you know that Rasmus, the creator of PHP, has recently given a talk at the <a href="http://digg.com/" target="_blank">Digg</a> office on PHP performance optimization?</p>
<p><object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13768954&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13768954&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object></p>
<p>Very interesting, specially because he shows us which tools he uses to measure the performance of websites. The presentation is inspiring. It motivated me to learn more about the solutions I use and try to <strong><em>really</em></strong> understand what happens under the hood. Rasmus has proven that that is the only way to get good optimization results.</p>
<p>The presentation also made me think about some things regarding the CakePHP framework, specially their concern on making the new versions of the framework backwards compatible with older versions of PHP and not using the PHP 5.3 features. I searched the web for some more &#8220;aggressive&#8221; frameworks and I really liked the <a href="http://www.recessframework.org">Recess Framework</a>. It&#8217;s sad to see that its development is stalled =/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/08/04/digg-technical-talks-rasmus-lerdorf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to Success</title>
		<link>http://www.josericardo.eti.br/2010/08/03/road-success/</link>
		<comments>http://www.josericardo.eti.br/2010/08/03/road-success/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 18:10:27 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[startup]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=942</guid>
		<description><![CDATA[I&#8217;ve just found a very nice illustration of &#8220;The Road to Success&#8221;. I really like the representations of &#8220;weak morals&#8221; and &#8220;lack o preparation&#8221;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just found a very nice illustration of &#8220;The Road to Success&#8221;.</p>
<p><a href="http://www.josericardo.eti.br/wp-content/uploads/2010/08/the-road-to-success.jpg"><img class="aligncenter size-medium wp-image-943" title="The Road to Success" src="http://www.josericardo.eti.br/wp-content/uploads/2010/08/the-road-to-success-260x300.jpg" alt="The Road to Success" width="260" height="300" /></a></p>
<p>I really like the representations of &#8220;weak morals&#8221; and &#8220;lack o preparation&#8221; <img src='http://www.josericardo.eti.br/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/08/03/road-success/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Cake on Steroids] Write-once Autocomplete Search</title>
		<link>http://www.josericardo.eti.br/2010/07/31/cake-steroids-write-once-autocomplete-search/</link>
		<comments>http://www.josericardo.eti.br/2010/07/31/cake-steroids-write-once-autocomplete-search/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 19:34:26 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/?p=602</guid>
		<description><![CDATA[Hi. Tired of having to write code for searches, usually autocompletes, over and over again? If you expect JSON as the outcome of your searches, like the JQuery UI&#8217;s Autocomplete does, you may find this post interesting. In my projects, I add the following function to my AppController to provide a fast search action to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi. Tired of having to write code for searches, usually autocompletes, over and over again? If you expect JSON as the outcome of your searches, like the <a href="http://docs.jquery.com/UI/Autocomplete">JQuery UI&#8217;s Autocomplete</a> does, you may find this post interesting.</p>
<p>In my projects, I add the following function to my AppController to provide a fast search action to all my controllers:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableCache</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$items</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>
     <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">modelClass</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$conditions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$conds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$model</span>.{<span style="color: #006699; font-weight: bold;">$conds</span>[<span style="color: #006699; font-weight: bold;">$i</span>]}&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$conds</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000088;">$get</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'get'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$get</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'get'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'term'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'term'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$selector</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;%<span style="color: #006699; font-weight: bold;">$id</span>%&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LOWER(<span style="color: #006699; font-weight: bold;">$model</span>.&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">') LIKE'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$selector</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$or</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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$or</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LOWER(<span style="color: #006699; font-weight: bold;">$model</span>.<span style="color: #006699; font-weight: bold;">$f</span>) LIKE&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$selector</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OR'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$or</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$args</span> <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;">=&gt;</span> <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$get</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// the id must come automatically</span>
          <span style="color: #000088;">$get</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$model</span>.id&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$get</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$model</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">recursive</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$model</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'items'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">autorender</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">viewPath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/elements'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'search'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>(The original code has been updated. Thanks to: dogmatic69 and Cauan Cabral)</em></p>
<p>Besides the search action. You also have to have a json.ctp file in your view/layouts dir with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content_for_layout</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now you&#8217;re ready to have it working. All you have to do to finally &#8220;enable&#8221; the feature is to place the view (search.ctp) in your views/elements dir:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$javascript</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Using the search</h2>
<p>Currently, the search function accepts the following three named parameters:</p>
<ul>
<li><strong>fields</strong>: the (comma separated) fields which we are going to compare against the <strong>term</strong> parameter.</li>
<li><strong>conditions</strong>: (pairs of comma separated) conditions  for the search</li>
<li><strong>get</strong>: which (comma separated) fields we want to receive from the search (the result)</li>
</ul>
<p>Now suppose you have a Post model in your application. If we want to:</p>
<ol>
<li>search for posts with &#8220;php&#8221; (<em>term</em> parameter) in the title or in it&#8217;s description (fields)</li>
<li>the posts must be <em>published</em> already and the author has the user id (<em>author_id</em> field) equals 4.</li>
<li>we want to retrieve only the <em>title</em> and <em>tags</em> fields</li>
</ol>
<p>To make the previous search, we can now use the following URL to receive our JSON result:</p>
<pre>

http://example.com/posts

/search/fields:title,description
/conditions:published,1,author_id=4
/get:title,tags
/?term=php
</pre>
<p>I think you got it, right? As always, I&#8217;m waiting for your comments. See ya.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/07/31/cake-steroids-write-once-autocomplete-search/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>[Cake on Steroids] PHP + JS</title>
		<link>http://www.josericardo.eti.br/2010/07/16/cake-steroids-php-js/</link>
		<comments>http://www.josericardo.eti.br/2010/07/16/cake-steroids-php-js/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 18:29:13 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/newblog/?p=26</guid>
		<description><![CDATA[Hi, today I&#8217;m starting a series of posts with tips on how to improve your CakePHP productivity even more. By productivity I mean: doing things faster and/or in a more organized way. I&#8217;m calling it &#8220;Cake on Steroids&#8221;. As I searched the web and could not find anything like this, I think it&#8217;s ok to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, today I&#8217;m starting a series of posts with tips on how to improve your CakePHP productivity even more. By productivity I mean: doing things faster and/or in a more organized way. I&#8217;m calling it &#8220;Cake on Steroids&#8221;. As I searched the web and could not find anything like this, I think it&#8217;s ok to use this name, right? Enough said, let&#8217;s start.</p>
<p>Well, one thing that really annoyed me since the first time I used CakePHP was the way Javascript is handled per default by the framework. It&#8217;s not hard to find views with stuff like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codeBlock</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'window.addEvent(&quot;domready&quot;, function(){alert(&quot;hi there);});'</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;inline&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The two main problems of writing JS code this way are:</p>
<ol>
<li>No editor can provide javascript syntax highlighting in PHP strings, right? This is a nightmare.</li>
<li>Javascript mixed with PHP and HTML code.</li>
</ol>
<p>We all know that the second reason can easily be solved in CakePHP, since the framework, obviously, allows us to use JS files. But there are some situations in which it would be nice to be able to use some PHP code within the Javascript code. For example, sometimes we use URLs in the javascript code (in an autocomplete function, for example) and the url() function from the Html helper is nice.</p>
<p>Another strong reason to use PHP + JS is to maintain consistency between elements in the view and the Javascript. What kind of elements? Images and, even more importantly for those who need it, translations. We just don&#8217;t want to have to translate things twice (one using cake and another using JS), right? Even if we could use the same translation file for PHP and JS, it would be nice to have elements attached to only one keyword, so we reduce the chances of making mistakes (eg. changing the keyword only in the PHP or only in the JS).</p>
<p>Well, as I said, all this annoyed me. And I think most people can figure out more scenarios in which it would be nice to have PHP + JS in their environments. So, the good news are that it is perfectly possible to do it in CakePHP.</p>
<p>I have found some articles which teach how to do it. Oh, I forgot to say. I&#8217;m using this solution for quite some time and I&#8217;ve been postponing this post for months and now I just couldn&#8217;t find my original sources. If I find them, I&#8217;ll update the post, ok?</p>
<p>So, how do we do it?</p>
<p>The first step is to tell cake to parse the js extension. You can do it by editing app/config/routes.php and adding the following statement:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Router<span style="color: #339933;">::</span><span style="color: #004000;">parseExtensions</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The second step is to add a default layout for JS. You can do it by creating and editing the file app/views/layouts/js/gen.ctp:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: application/x-javascript&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content_for_layout</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'debug'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The third and last step is to create an action in a controller which will be responsible for loading our JS file. I like to add this action to my AppController, so I don&#8217;t have to write it in all my controllers. Edit you AppController and add the following function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> formjs<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ext'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gen'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'.js'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cacheDuration&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1 hour'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Adding this function to my AppController allows me to add the following lines to my default layout (usually app/views/layouts/default.ctp):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoloadFormJs</span> <span style="color: #339933;">=</span> APP <span style="color: #339933;">.</span> <span style="color: #0000ff;">'views'</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> this<span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;controller&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;js&quot;</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;formjs.js&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$urlAction</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$urlAction</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'add'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$urlAction</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'edit'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$autoloadFormJs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$jsPath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;controller&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/formjs/1'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$jsPath</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></div></div>

<p>and voilá. All you have to do is create a js/formjs.js file inside the view folder of your component and it will be inserted automatically. For example, if you have a component called <em>bodies</em>, and you want some javascript to be automatically loaded for the <em>add</em> and <em>edit</em> actions, all you have to do is create the file <em>views/bodies/js/formjs.js</em> and the code above will insert the file automatically in the page.</p>
<p>Of course, I&#8217;m just trying to speed up your development process <img src='http://www.josericardo.eti.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  But you can be more conservative and place the formjs function only in the bodies controller. Or you can load the javascript only in the add.ctp view of the bodies component. To do it, you would have to place following line in your views/bodies/add.ctp file:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$javascript</span> <span style="color: #339933;">-&gt;</span> <span style="color: #990000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/bodies/formjs/1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A positive side-effect of this approach is that you can pass the <em>id</em> argument in the javascript URL. In the examples above, all links to javascript files use the <em>id</em> = 1. But you can use different values for the id and the javascript file will be loaded the same way. This is actually a feature of this approach, since you can use aggressive caching policies for your javascript files and change the <em>id</em> whenever the file is modified, assuring consistency.</p>
<p>Now our javascript files are being loaded by the CakePHP framework and we can use PHP inside of them in anyway we want.</p>
<p>I usually write the PHP code inside javascript comments, so the editor does not give me syntax errors. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*&lt;?php
$usersAutocompleteUrl = $html-&gt;url(array('controller' =&gt; 'users', 'action' =&gt; 'autocomplete'));
*/</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// using the previously defined PHP variable</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#userSearchField'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;?= $usersAutocompleteUrl ?&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// lots of JS code</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, I created a helper called PhpInJS to help me define variables in the PHP view which can be used in a JS file. Place the following code in the <em>views/helpers/php_in_js.php</em> file:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> PhpInJsHelper <span style="color: #000000; font-weight: bold;">extends</span> AppHelper <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PhpInJs'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$controller</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PhpInJs'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PhpInJs'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</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></div></div>

<p>You can use this helper in the view file (eg. add.ctp) to set a variable:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$eraseImage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$phpInJs</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'eraseImage'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">image</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'erase.png'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// use the $eraseImage var in the PHP file</span></pre></div></div>

<p>and use the the same value in the JS file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*&lt;?php
$eraseImage = $phpInJs -&gt; get('eraseImage');
?&gt;*/</span></pre></div></div>

<p>Well, I think it&#8217;s enough. You can/should always use the comments to help me improve/fix the solution, ok? See ya.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/07/16/cake-steroids-php-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Welcome to the new version of my blog</title>
		<link>http://www.josericardo.eti.br/2010/07/07/4/</link>
		<comments>http://www.josericardo.eti.br/2010/07/07/4/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 15:07:38 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/newblog/?p=4</guid>
		<description><![CDATA[Hi, after some experiences with wordpress and drupal, I decided to switch back to WordPress. I hope you all enjoy this new version. I&#8217;m planning to use this new version of the blog to expose more of my technical discoveries, specially regarding web development. Despite the fact that I&#8217;m Brazilian, the default version of the [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, after some experiences with wordpress and drupal, I decided to switch back to WordPress. I hope you all enjoy this new version. I&#8217;m planning to use this new version of the blog to expose more of my technical discoveries, specially regarding web development.</p>
<p><span style="font-size: 13.3333px;">Despite the fact that I&#8217;m Brazilian, the default version of the blog is the English one, because I want to keep myself practicing the few English words I know. Of course, sometimes there will be posts that will concern only Brazilian people, and I will post only the Portuguese version.</span></p>
<p>Well. I think it&#8217;s enough for ANOTHER welcome post. See ya.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/07/07/4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Before your next meeting, just think about it</title>
		<link>http://www.josericardo.eti.br/2010/07/05/before-your-next-meeting-just-think-about-it/</link>
		<comments>http://www.josericardo.eti.br/2010/07/05/before-your-next-meeting-just-think-about-it/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 15:15:01 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[lifehacking]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/newblog/?p=19</guid>
		<description><![CDATA[&#8220;When you think about it, the true cost of meetings is staggering. Let’s say you’re going to schedule a meet- ing that lasts one hour, and you invite ten people to at- tend. That’s actually a ten-hour meeting, not a one-hour meeting. You’re trading ten hours of productivity for one hour of meeting time. And [...]]]></description>
			<content:encoded><![CDATA[<div>
<blockquote><p><em>&#8220;When you think about it, the true cost of meetings<br />
is staggering. Let’s say you’re going to schedule a meet-<br />
ing that lasts one hour, and you invite ten people to at-<br />
tend. </em><strong><em>That’s actually a ten-hour meeting</em></strong><em>, not a one-hour<br />
meeting. You’re trading ten hours of productivity for<br />
one hour of meeting time. And it’s probably more like<br />
fifteen hours, because there are mental switching costs<br />
that come with stopping what you’re doing, going<br />
somewhere else to meet, and then resuming what you<br />
were doing beforehand.&#8221;</em></p></blockquote>
<p style="text-align: right;"><em>Jason Fried &amp; David Hansson, Rework</em></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/07/05/before-your-next-meeting-just-think-about-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple sessions for different instances of Cakephp in the same domain</title>
		<link>http://www.josericardo.eti.br/2010/05/26/multiple-sessions-for-different-instances-of-cakephp-in-the-same-domain/</link>
		<comments>http://www.josericardo.eti.br/2010/05/26/multiple-sessions-for-different-instances-of-cakephp-in-the-same-domain/#comments</comments>
		<pubDate>Wed, 26 May 2010 15:13:40 +0000</pubDate>
		<dc:creator>zehzinho</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.josericardo.eti.br/newblog/?p=17</guid>
		<description><![CDATA[Did you know that if you run multiple instances of the same application in Cakephp in the same domain, they will share the same Session? For example, suppose you have instances running at: www.example.com/instance1 and www.example.com/instance2 If you login in the first instance and access instance2, you&#8217;ll see that you will already be logged in. This [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that if you run multiple instances of the same application in Cakephp in the same domain, they will share the same Session? For example, suppose you have instances running at:</p>
<p><a title="www.example.com/instance1" href="http://www.example.com/instance1">www.example.com/instance1</a> and <a title="www.example.com/instance2" href="http://www.example.com/instance2">www.example.com/instance2</a></p>
<p>If you login in the first instance and access instance2, you&#8217;ll see that you will already be logged in. This happens because Cakephp, per default, uses the PHP Session storage mechanism.</p>
<p>If this is not the behaviour you expect, Cakephp allows you to choose from three options for the Session handling method: <em>php</em> (default), <em>cake</em> and <em>database</em>. The current method is stored in the <em>Session.save</em> variable in app/config/core.php.</p>
<p>Changing the method from <em>php</em> to <em>cake</em> will make Cakephp store the Session variables in the app/tmp/sessions directory. If you do it, remember to create and give the appropriate permissions to this directory.</p>
<p>Voilá, that&#8217;s all you need to do have separate Sessions for each of your Cakephp instances.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josericardo.eti.br/2010/05/26/multiple-sessions-for-different-instances-of-cakephp-in-the-same-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
