Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Cook up Web sites fast with CakePHP, Part 4: Use CakePHP's Session and Request Handler components

Streamline PHP applications

Sean Kelly (skelly@idsociety.com), Web Application Developer, ID Society
Sean Kelly graduated with a degree in mathematics from Reed College. He is currently a Web application developer for ID Society, a full-service Internet marketing agency in New York City. He is a supporter of open source content management systems, and contributes to Joomla! and the Wikipedia project.

Summary:  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. Part 4 focuses primarily on the Session component of CakePHP, demonstrating three ways to save session data, as well as the Request Handler component to help you manage multiple types of requests (mobile browsers and requests containing XML or HTML).

View more content in this series

Date:  08 Feb 2011 (Published 02 Jan 2007)
Level:  Intermediate PDF:  A4 and Letter (269 KB | 28 pages)Get Adobe® Reader®

Activity:  45242 views
Comments:  

Before you start

Editor's note: This series was originally published in 2006, and has undergone several revisions since in order to keep up with ongoing developments on CakePHP. This revision was written for CakePHP V1.3.4.

This "Cook up Web sites fast with CakePHP" series is designed for PHP application developers who want to start using CakePHP to make their lives easier. In the end, you will have learned how to install and configure CakePHP, the basics of Model-View-Controller (MVC) design, how to validate user data in CakePHP, how to use CakePHP helpers, and how to get an application up and running quickly using CakePHP. It might sound like a lot to learn, but don't worry — CakePHP does most of it for you.

About this series

  • Part 1 focuses on getting CakePHP up and running, and the basics of how to put together a simple application allowing users to register for an account and log in to the application.
  • Part 2 demonstrates how to use scaffolding and Bake to get a jump-start on your application, and how to use CakePHP's access control lists (ACLs).
  • Part 3 shows how to use Sanitize, a handy CakePHP class, which helps secure an application by cleaning up user-submitted data. It also covers the CakePHP security component, handling invalid requests, and other advanced request authentication.
  • Part 4 focuses primarily on the Session component of CakePHP, demonstrating three ways to save session data, as well as the Request Handler component to help you manage multiple types of requests (mobile browsers and requests containing XML or HTML).
  • Part 5 deals with caching, specifically view and layout caching, which can help reduce server resource consumption and speed up your application.

About this tutorial

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:

  • The different types of session handling covered by CakePHP — You will learn the advantages and disadvantages of each, and how to implement them.
  • How to use the Request Handler in your controllers — We will use it for two purposes: to add an RSS feed of your products and to implement Ajax functionality.

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 PHP, 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.3.2.
  3. A supported database engine. This tutorial was written using MySQL V5.0.67.

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 CakePHP.org and download the latest stable version from the Downloads section. This tutorial was written using V1.3.4 (see Resources).

1 of 8 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=390856
TutorialTitle=Cook up Web sites fast with CakePHP, Part 4: Use CakePHP's Session and Request Handler components
publish-date=02082011
author1-email=skelly@idsociety.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.