<?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>Rick Guyer .com &#187; CakePHP</title>
	<atom:link href="http://rickguyer.com/tag/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://rickguyer.com</link>
	<description>Information about the web, web development, and technology.</description>
	<lastBuildDate>Wed, 21 Sep 2011 13:50:15 +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>SmartRedirect Plugin for CakePHP</title>
		<link>http://rickguyer.com/smartredirect-plugin-for-cakephp/</link>
		<comments>http://rickguyer.com/smartredirect-plugin-for-cakephp/#comments</comments>
		<pubDate>Thu, 07 May 2009 18:24:21 +0000</pubDate>
		<dc:creator>ricog</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://rickguyer.com/?p=46</guid>
		<description><![CDATA[When adding, editing, or deleting records in a web application, it is common to return the user to where they originated. That is what they typically expect. The SmartRedirect plugin allows just that, without any coding in your models, controllers, or views.]]></description>
			<content:encoded><![CDATA[<p>When adding, editing, or deleting records in a web application, it is common to return the user to where they originated. That is what they typically expect. The SmartRedirect plugin allows just that, without any coding in your models, controllers, or views.</p>
<p>You can grab the plugin using git or by zip from the <a href="http://github.com/ricog/smart_redirect">SmartRedirect Plugin project page</a> on <a href="http://github.com">GitHub</a>.</p>
<p>All you need to do is extract the file and drop the smart_redirect folder into your app/plugins directory. After that, add SmartRedirect.AutoReturn to your components list. Something like this:</p>
<pre class="brush: php">
var $components = array(&#039;SmartRedirect.AutoReturn&#039;);
</pre>
<p>Now when you add, edit, or delete records in your application, you&#8217;ll be returned to the page you were on before.</p>
<p>The plugin does use a custom view, so may conflict with other plugins such as <a href="http://thechaw.com/debug_kit">Debug Kit</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rickguyer.com/smartredirect-plugin-for-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reusing controller views in CakePHP</title>
		<link>http://rickguyer.com/reusing-controller-views-in-cakephp/</link>
		<comments>http://rickguyer.com/reusing-controller-views-in-cakephp/#comments</comments>
		<pubDate>Sat, 02 May 2009 15:50:36 +0000</pubDate>
		<dc:creator>ricog</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://rickguyer.com/?p=37</guid>
		<description><![CDATA[CakePHP makes it easy to reuse your small blocks of presentation code throughout your application by using Elements. You can read more about them here: http://book.cakephp.org/view/97/Elements Sometimes though you want to reuse a regular controller view without moving the code to an element. In fact, if the view code is specific to the controller, it [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP makes it easy to reuse your small blocks of presentation code throughout your application by using <a href="http://book.cakephp.org/view/97/Elements">Elements</a>. You can read more about them here:</p>
<p><a href="http://book.cakephp.org/view/97/Elements">http://book.cakephp.org/view/97/Elements</a></p>
<p>Sometimes though you want to reuse a regular controller view without moving the code to an element. In fact, if the view code is specific to the controller, it is good practice to keep it in the controller view.</p>
<p>Fortunately this is fairly simple. Just create the view and then reference it like this:</p>
<pre class="brush: php">
&lt;?php echo $this-&gt;element(&#039;../projects/menu&#039;); ?&gt;
</pre>
<p><em>In the example above, I&#8217;m accessing the following file: /views/projects/menu.ctp</em></p>
<p>As always, the element will have access to all existing view variables (t<em>he ones typically passed using $this-&gt;set()</em>).</p>
]]></content:encoded>
			<wfw:commentRss>http://rickguyer.com/reusing-controller-views-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP: One core, many apps</title>
		<link>http://rickguyer.com/cakephp-one-core-many-apps/</link>
		<comments>http://rickguyer.com/cakephp-one-core-many-apps/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:55:36 +0000</pubDate>
		<dc:creator>ricog</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://ricoguyer.com/?p=25</guid>
		<description><![CDATA[CakePHP allows you to use one set of core files while maintaining multiple applications. It only takes a few steps, but may not be completely straightforward the first time you try. In my example, I have my workspace in ~/dev. I would setup my project in ~/dev/client_name/project_name. I place my cake core files in separate [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP allows you to use one set of core files while maintaining multiple applications. It only takes a few steps, but may not be completely straightforward the first time you try. In my example, I have my workspace in ~/dev. I would setup my project in  ~/dev/client_name/project_name. I place my cake core files in separate folders for each version in ~/dev/lib/cakephp.</p>
<p><strong>The basics</strong></p>
<ol>
<li>Download and install the latest version of <a href="http://cakephp.org/">CakePHP</a> in a good location.<br /><i>Examples:</i>
<ul>
<li>Linux: /usr/lib/cakephp/cake_1.2.2.8120</li>
<li>Windows: C:\lib\cakephp\cake_1.2.2.8120</li>
</ul>
</li>
<li>Copy the contents of the app folder to your project root. This is typically your webserver root or a folder within.</li>
<li>Edit the following constants in webroot/index.php:
<ol>
<li>ROOT<br />You&#8217;ll want to change it so the root is one level back (your project root)
<pre class="brush: php">
	if (!defined(&#039;ROOT&#039;)) {
		define(&#039;ROOT&#039;, dirname(dirname(__FILE__)));
	}
</pre>
</li>
<li>APP_DIR<br />This one just gets set to blank since your root is also your app folder
<pre class="brush: php">
	if (!defined(&#039;APP_DIR&#039;)) {
		define(&#039;APP_DIR&#039;, &#039;&#039;);
	}
</pre>
</li>
<li>CAKE_CORE_INCLUDE_PATH<br />Set the path to your cake core files. This can either be relative (../../core) or absolute (/path/to/core)
<pre class="brush: php">
	if (!defined(&#039;CAKE_CORE_INCLUDE_PATH&#039;)) {
		define(&#039;CAKE_CORE_INCLUDE_PATH&#039;, &#039;..&#039;.DS.&#039;..&#039;.DS.&#039;..&#039;.DS.&#039;lib&#039;.DS.&#039;cakephp&#039;.DS.&#039;cake_1.2.2.8120&#039;);
	}
</pre>
<p>or</p>
<pre class="brush: php">
	if (!defined(&#039;CAKE_CORE_INCLUDE_PATH&#039;)) {
		define(&#039;CAKE_CORE_INCLUDE_PATH&#039;, DS.&#039;usr&#039;.DS.&#039;lib&#039;.DS.&#039;cakephp&#039;.DS.&#039;cake_1.2.2.8120&#039;);
	}
</pre>
</li>
</ol>
</li>
</ol>
<p>It may take a little work to get the paths right, but it is well worth it. If you try to access your project and you get PHP errors, it probably means something is wrong with the core path above. The next project you start, just copy the app folder again as above, and copy the same index.php into any new projects you start.</p>
<p><strong>Different paths for dev and live</strong><br />
The above example only covers one server configuration. Some developers may be developing in Windows while their production server runs Linux. In that case you will need to account for each server. A simple if/else statement will take care of this. In my case, I have &#8220;localdev&#8221; as the hostname for my local development server. Here is what my CAKE_CORE_INCLUDE_PATH configuration looks like:</p>
<pre class="brush: php">
	if (!defined(&#039;CAKE_CORE_INCLUDE_PATH&#039;)) {
		if ($_SERVER[&#039;SERVER_NAME&#039;] == &#039;localdev&#039;) {
			define(&#039;CAKE_CORE_INCLUDE_PATH&#039;, &#039;..&#039;.DS.&#039;..&#039;.DS.&#039;..&#039;.DS.&#039;lib&#039;.DS.&#039;cakephp&#039;.DS.&#039;cake_1.2.2.8120&#039;);
		} else {
			define(&#039;CAKE_CORE_INCLUDE_PATH&#039;, DS.&#039;usr&#039;.DS.&#039;lib&#039;.DS.&#039;cakephp&#039;.DS.&#039;cake_1.2.2.8120&#039;);
		}
	}
</pre>
<p><strong>Upgrading CakePHP</strong><br />
Upgrading CakePHP is pretty easy. Just install the latest version of CakePHP as described above. Then when you are ready to upgrade your app, change the core path again and start testing. If you run into issues with the latest version, it is really easy to switch back.</p>
]]></content:encoded>
			<wfw:commentRss>http://rickguyer.com/cakephp-one-core-many-apps/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Letting multiple CakePHP apps talk</title>
		<link>http://rickguyer.com/letting-multiple-cakephp-apps-talk/</link>
		<comments>http://rickguyer.com/letting-multiple-cakephp-apps-talk/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 02:38:50 +0000</pubDate>
		<dc:creator>ricog</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[webservice]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://ricoguyer.com/?p=21</guid>
		<description><![CDATA[CakePHP is getting really popular, so naturally, there are quite a few sites out there using it. If you&#8217;ve been using CakePHP long enough, sooner or later you will want to have 2 or more of those apps talk to each other. Setting CakePHP up to act as a webservice is pretty easy. Teaching the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cakephp.org">CakePHP</a> is getting really popular, so naturally, there are quite a few sites out there using it. If you&#8217;ve been using CakePHP long enough, sooner or later you will want to have 2 or more of those apps talk to each other. <a href="http://book.cakephp.org/view/477/The-Simple-Setup">Setting CakePHP up to act as a webservice</a> is pretty easy. Teaching the other apps to talk to that webservice takes a little more work. Jesse (over at <a href="http://techno-geeks.org">TechnoGeeks</a>) and I have been working on just that.</p>
<p>So far we have one app authenticating against the other. This can be very useful if you have a central user database, and don&#8217;t want to maintain users across every application you create. We used XML as the transport, so this could easily be used for applications that aren&#8217;t written in CakePHP. You can get all the details in Jesse&#8217;s article: <a href="http://techno-geeks.org/2009/03/authenticating-a-cakephp-app-against-a-cakephp-webservice/">Authenticating a CakePHP App Against a CakePHP Webservice</a>.</p>
<p>We hope to extend it and allow standardized CRUD functionality across the applications. During that time, we may move the code into a datasource. But who knows.</p>
]]></content:encoded>
			<wfw:commentRss>http://rickguyer.com/letting-multiple-cakephp-apps-talk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speeding up count queries with counterCache</title>
		<link>http://rickguyer.com/speeding-up-count-queries-with-countercache/</link>
		<comments>http://rickguyer.com/speeding-up-count-queries-with-countercache/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 01:18:42 +0000</pubDate>
		<dc:creator>ricog</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://ricoguyer.com/?p=8</guid>
		<description><![CDATA[Today while working in a CakePHP application, I needed to hide some records based on the number of associated records they had. I basically needed to get a count of associated records. Fortunately, CakePHP has a feature called counterCache that makes this really easy. It saves the record count in the database and updates the [...]]]></description>
			<content:encoded><![CDATA[<p>Today while working in a <a href="http://cakephp.org">CakePHP</a> application, I needed to hide some records based on the number of associated records they had. I basically needed to get a count of associated records. Fortunately, CakePHP has a feature called <a href="http://book.cakephp.org/view/490/counterCache-Cache-your-count">counterCache</a> that makes this really easy. It saves the record count in the database and updates the count any time you do a save or delete. The details can be found here:  <a href="http://book.cakephp.org/view/490/counterCache-Cache-your-count">http://book.cakephp.org/view/490/counterCache-Cache-your-count</a></p>
<p>Basically you do the following:</p>
<ol>
<li>Create an INT field on the parent table called &lt;childmodelname&gt;_count</li>
<li>In the $belongsTo array of the child model, add &#8220;&#8216;counterCache&#8217; =&gt; true&#8221; to the parent array</li>
<li>Enjoy!</li>
</ol>
<p>This works great for new installations. However, if you want to add it to an existing site, you&#8217;ll need to run through all the records and save the current count. Here is a sample method for doing just that.</p>
<pre class="brush: php">
function admin_update_counters() {
$this-&gt;Category-&gt;recursive = 0;
$categories = $this-&gt;Category-&gt;find(&#039;all&#039;);
foreach ($categories as $category) {
$question_count = $this-&gt;Category-&gt;Question-&gt;find(&#039;count&#039;, array(&#039;conditions&#039; =&gt; array(&#039;Question.category_id&#039; =&gt; $category[&#039;Category&#039;][&#039;id&#039;])));
if ($question_count) {
$this-&gt;Category-&gt;create();
$this-&gt;Category-&gt;id = $category[&#039;Category&#039;][&#039;id&#039;];
$this-&gt;Category-&gt;saveField(&#039;question_count&#039;, $question_count);
}
}

echo &quot;Counters updated&quot;; exit;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://rickguyer.com/speeding-up-count-queries-with-countercache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

