Book Image

CakePHP 2 Application Cookbook - Third Edition

By : Watts
Book Image

CakePHP 2 Application Cookbook - Third Edition

By: Watts

Overview of this book

If you are a CakePHP developer looking to ease the burden of development, then this book is for you. As a headfirst dive into the framework, this collection of recipes will help you get the most out of CakePHP, and get your applications baked in no time. Even if you're not familiar with the framework, we'll take you from basic CRUD building to useful solutions that will aid in getting the job done quickly and efficiently.
Table of Contents (14 chapters)
13
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...