zen of coding

amCharts with CakePHP

There is a very slick flash charting tool out there called amCharts (www.amcharts.com). If you are in need of some reporting or charting UI for your application, I strongly recommend it. This is a quick guide on how to get it working with CakePHP. For this example, I’ll show you how[…]

Read More »

CakePHP and custom SQL

If you’ve been around CakePHP for some time, you’ve probably heard that writing custom SQL is pretty much frowned upon. At the core, CakePHP provides some clever ways to write queries by employing the find() and save() methods, yet in some cases it is just impossible to use find() or save()[…]

Read More »

Redirecting to the home page

Sometimes you’d like to create a link that will redirect your traffic to the homepage. For example, you have some partner web site that will drive traffic to a URL like: www.yoursite.com/partnerName. This way you’ll be able to track this link in the web site logs. Just add the following[…]

Read More »

Don't forget your primary key

If are you are using a non-standard column name for your primary key (something other than ‘id’), maybe from a legacy database, it is very important not to forget to set the var $primaryKey in your model. This little oversight can break a lot of things without giving any clue[…]

Read More »

JSON output with CakePHP

Update (2/14/2011): Take a look at a more robust approach that works with recent 1.3 versions of CakePHP. Update (9/25/2008): Since the writing of this post, the CakePHP manual has been updated with information on using the RequstHandler, which is an excellent supplement to the approach described below. You should[…]

Read More »

JQuery autocomplete in CakePHP

Update to this post is here. (New libraries and new techniques are discussed). This is a quick example on how to setup an autocomplete field using JQuery and CakePHP. Let’s assume that we have a Product model and products controller. Our goal is to allow the user to type in[…]

Read More »

Multiple checkboxes

One question that I’ve seen come up a few times is: “How do I handle multiple checkboxes in a form?” The only trick here is the way you name your checkbox form element. Let’s consider an example where you’d like to select multiple messages (by using checkboxes) and then delete[…]

Read More »

Hooray JQuery

I’ve completely abandoned using Prototype/Scriptaculous in favor of JQuery. I simply prefer the way JQuery does things: Simple syntax No more in-line JS Lots of great plug-ins JQuery UI has some very nice widgets Lightweight In terms of CakePHP it means that I can no longer rely on the built-in[…]

Read More »

Excellent HTML table helper

If your application requires to display a lot of data from the DB, then I suggest you take a look at this nice, little HTML table helper: http://cakeforge.org/snippet/detail.php?type=snippet&id=162 Basically it will allow you to pass a data array from the find method and it will construct an HTML table with[…]

Read More »

CSS files and $scripts_for_layout

You probably know that if you have $scripts_for_layout in your site’s layout, then you can include JS files from the view. For example, if you’d like to include ‘myScript.js’ from some view you would add the following code: $javascript->link(‘myScript’, false); Basically the second param (false), will tell CakePHP not to include[…]

Read More »
%d bloggers like this: