Feed items

Share Your CakePHP Core and Application Files Server Wide

If you are deploying several Cake applications server wide you may want to keep the Cake core in one central place so that it can be easily updated.  In order to do this place the cake core directory somewhere on your server where is can be accessed.  For example /usr/lib/php/cake.  Then, when you create your applications open up your root index file  and replace the following:
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT);
}

with this:
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH',
DS . 'usr' . DS . 'lib' . DS . 'php' . DS . 'cake');
}

You are now using the common cake core. When a new update comes out to the library, just replace the files in /usr/lib/php/cake with the new version!

Cache Your Queries or Data Arrays in CakePHP

In a recent CMS project in CakePHP I was loading in some website settings to use nearly on every page.  These settings are not updated very often, so I figured I would cache the query.  The method of caching data I am going to outline can be done not just for queries… but for any kind of data really.  Lets get started!
The Cache Function
CakePHP’s cache function is quite easy to use.  The code snippet below shows how to use it.

Tip: Build Forms Quicker in CakePHP

I first saw use of the $form->inputs() function for building a form on Johnathan Snook’s blog post about creating a contact form.  After investigating further into the function, I found that it can be used to save quite a bit of time.
Automagic Forms!
Using $form->input() is great, but when you have many fields or you are just creating a quick form there is a better way!  The key is to set up your database table structure properly.  If you follow the naming conventions creating a form is as easy as using the following code in the view (this is for a Contact model… obviously):

Beginning CakePHP: The MVC Mindset

The manual for CakePHP has a pretty basic explanation of what MVC is.  This article will explain things in a little more detail because the MVC pattern is crucial when it comes to using CakePHP.  If you are not familiar with the MVC design pattern, read on…
What is MVC anyway?
MVC stands for Model-View-Controller.  MVC is a well known design pattern that basically keeps that data handling, application flow, and presentation seperate from each other.  At first it may seem a little confusing, but it makes coding much easier and efficient.  I will explain each aspect of the MVC below relative to a simple application to manage contacts.