CakePHP Framework

Database Sessions with CakePHP 1.3 in 1 minute

Enabling database sessions with CakePHP 1.3 is super easy. But first I want to cover a few reasons that I know of where you need sessions stored in the database: load-balanced environments and PHP file-locking issues.

Read ›

CakePHP Containable Behavior Example

Recently a client needed a long page with a lot of data. I found CakePHP's Containable Behavior to be a quick and effective way to perform complex queries efficiently. Containable makes queries efficient because you only join the tables you need and you only fetch the columns whose values you need.

Below is an example that is similar to my code. Say you have a requirement to put 10 blog posts on a page, complete with associated slideshows and comments. Maybe it is a crazy web page or maybe it is the result of an API call. Anyhow, imagine your blog posts have an author who has an avatar. Each post may have a slideshow with any number of images. Posts may have many of comments and we want the comment text as well as the comment authors' names, emails, and avatars.

Read ›

CakePHP Session Cookie Path

In CakePHP I needed a way to have an app at "/app" but be able to share session data with another app. The easiest way is to set the Session Cookie path to "/". The problem is that Cake sets the session cookie to the base path--in this case "/app". There is no setting to override this behavior. But I discovered that if you start the session yourself, you can specify "/". Here is the code.

Read ›