Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

RESTful resources


You may have heard of REST at some point during your time in development. Representational State Transfer is an API architecture design which exposes resources over a stateless communication, using the HTTP methods of the protocol to facilitate polymorphism through a simplified and uniform API interface.

In this recipe we'll look at how easily REST can be implemented in CakePHP by leveraging the functionality provided by the framework.

Getting ready

For this recipe, we'll set up some standard and custom REST endpoints, which will act against a model. For this, create a table named posts using the following SQL statement:

CREATE TABLE posts (
  id INT NOT NULL AUTO_INCREMENT,
  title VARCHAR(255) NOT NULL,
  content TEXT,
  created DATETIME,
  modified DATETIME,
  PRIMARY KEY(id)
);

Then, we'll add some sample data using the following SQL statement:

INSERT INTO posts (title, content, created, modified)
VALUES
('Baking cakes', 'Baking is easy with CakePHP', NOW(), NOW()),
('How...