<?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 &#187; php</title>
	<atom:link href="http://www.josericardo.eti.br/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.josericardo.eti.br</link>
	<description>For those things that don&#039;t fit in 140 characters</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:08:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<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>4</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>[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>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>

