DevX HomePage

Cook Up Web Sites Fast with CakePHP, Part 4: Use CakePHP's Session and Request Handler Components

There are multiple ways of saving session data using CakePHP's Session component, and each method has its advantages. In this tutorial, you'll learn how to use the Session component by incorporating all three ways into your application, so you'll be able to pick the best one that works for you. On top of that, you'll learn how to use the Request Handler component to aid in your handling of various HTTP requests, including requests from mobile browsers, or requests containing XML or HTML content.

Level: Intermediate

Sean Kelly (skelly@idsociety.com), Web Application Developer, ID Society

02 Jan 2007
Updated 22 Jan 2008

Register now or sign in using your IBM ID and password.

CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.

In this tutorial

Editor's note: This series was originally published in 2006 and 2007. Since its publication, CakePHP developers made significant changes to CakePHP, which made this series obsolete. In response to these changes and the popularity of this series, the authors revised each of its five parts to make it compliant with the version of CakePHP available in January 2008.

There are multiple ways of saving session data using CakePHP's Session component, and each method has its advantages. In this tutorial, you'll learn how to use the Session component by incorporating all three ways into your application, so you'll be able to pick the best one that works for you. On top of that, you'll learn how to use the Request Handler component to aid in your handling of various HTTP requests, including requests from mobile browsers, or requests containing XML or HTML content.

This tutorial is divided into two main topics:


Prerequisites

This tutorial assumes you have already completed Part 1, Part 2, and Part 3, and that you still have the working environment you set up for those tutorials. If you do not have CakePHP installed, you should run through Parts 1 and 2 before continuing.

It is assumed that you are familiar with the PHP programming language, have a fundamental grasp of database design, and are comfortable getting your hands dirty.

For the section on Ajax, it is also assumed that you have a basic understanding of Ajax. See Resources for links to help you get started with Ajax.


System requirements

Before you begin, you need to have an environment in which you can work. CakePHP has reasonably minimal server requirements:

  1. An HTTP server that supports sessions (and preferably mod_rewrite). This tutorial was written using Apache V2.2.4 with mod_rewrite enabled.
  2. PHP V4.3.2 or later (including PHP V5). This tutorial was written using PHP V5.2.3
  3. A supported database engine. this tutorial was written using MySQL V5.0.4

You'll also need a database ready for your application to use. The tutorial will provide syntax for creating any necessary tables in MySQL.

The simplest way to download CakePHP is to visit CakeForge.org and download the latest stable version. This tutorial was written using V1.2.0. Nightly builds and copies straight from Subversion are also available. Details are in the CakePHP Manual.



Formats

html, pdf