Feed items

Queries across multiple databases with CakePHP

Most CakePHP documentation assumes you’ll be working with tables in the same database. However, how do you query related data when your tables are spread across multiple databases? Fortunately, CakePHP makes this a breeze with the CakePHP model’s ‘useDbConfig’ variable and a little table prefix manipulation I picked up from this post in the CakePHP [...]

Basic search with CakePHP Part 2 – search criteria

This is part 2 of the Basic search with CakePHP where we’ll present the search criteria in a more user-friendly way. The files here build on part 1.
Here’s the working example.

When presenting search criteria, it’s helpful to indicate what criteria will return the most results. In the example, you can see the criteria is listed [...]

How to not lose URL params on form validation errors with CakePHP

This problem makes me crazy every time I run into it. And the thing is, I know I’ve fixed it before and can never remember how. So I’m making this post as much for me as anyone else who may be stuck with losing URL parameters when a validation error occurs on a form.
Here’s a [...]

Basic search with CakePHP Part 1 – HABTM, joins and pagination

This will be a multi-part demonstration for building basic search functionality using CakePHP. Part 1 focuses on searching across models that have HasAndBelongsToMany relationships. Here’s a working demo of Part 1.
You see this type of search when looking for items that share similar properties. In the demo, it’s Bars that have Features (WiFi, TV, etc), [...]

UPDATE – An easy and intelligent pagination menu for CakePHP

I’ve been meaning to write an update to this post and supply a working demo….so here you go. Check out the demo. Please notice the letters “H”, “I”, “J” and “R” are ghosted because there are no user records beginning with that letter in the database.
In the last post I showed you how to create a [...]

Breaking up a form across multiple pages in CakePHP

Most CakePHP form examples present all the fields on one page and assume users fill everything out at once. But there may be a time when you need to spread a model’s form fields over multiple pages.
This approach brings with it a few important requirements.
1. You should allow the user to go [...]

An easy and intelligent pagination menu for CakePHP

I recently needed to create a typical paginated directory page where people could browse via an alphabetical menu. So clicking ‘A’ returns all entries that begin with ‘A’, ‘B’ with ‘B’ and so on. CakePHP’s Paginator Helper made this all very easy.
However, there was one tricky requirement….in the menu, if there were no records [...]

CakePHP and file upload validation

I haven’t seen an approach to file upload validation explicitly laid out in the CakePHP documentation. In other words, how do you make sure the user has selected a file to upload before hitting the upload button. In my case, I’m uploading images. After trying a few things, here’s what I’ve used.
It may seem logical [...]

Setting up a CakePHP project in Aptana Studio and Aptana Cloud

If you ‘re not familiar with Aptana Studio or Aptana Cloud, you can get all the details at www.aptana.com. But briefly, Aptana Studio is an IDE (Integrated Development Environment…think Eclipse, Dreamweaver, etc.) that hooks into Aptana’s hosting service called Aptana Cloud. Both products/services offer a long list of features that should catch your eye. This [...]