CakePHP Cookbook Documentation
Release 2.x
Cake Software Foundation
Mar 17, 2024
Contents
1 Getting Started
.
.
Blog Tutorial
Blog Tutorial - Adding a layer
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 Installation
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
Requirements .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
License
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Downloading CakePHP .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
Permissions .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
Setup . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
Development
Production .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
Advanced Installation and URL Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Fire It Up .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3 CakePHP Overview
What is CakePHP? Why use it? .
Understanding Model-View-Controller .
.
Where to Get Help .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
4 Controllers
.
.
.
.
.
.
.
The App Controller .
.
Request parameters .
Controller actions .
.
.
Request Life-cycle callbacks
.
Controller Methods .
.
Controller Attributes
.
More on controllers .
.
.
.
.
.
.
5 Views
View Templates .
.
Using view blocks .
.
Layouts
.
.
Elements .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1
9
29
29
30
30
30
31
31
32
32
36
37
37
38
40
43
43
44
44
45
46
53
55
77
77
79
81
83
i
Creating your own view classes .
.
View API
.
.
.
More about Views .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6 Models
Understanding Models
.
More on models .
.
7 Core Libraries
General Purpose .
.
Behaviors .
.
.
Components .
.
.
Helpers
.
.
.
Utilities .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8 Plugins
.
How To Install Plugins
How To Use Plugins .
.
How To Create Plugins .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
86
87
89
197
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
.
.
333
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
529
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9 Shells, Tasks & Console Tools
.
.
.
.
The CakePHP console .
.
.
.
Creating a shell
Shell tasks .
.
.
.
.
Invoking other shells from your shell .
.
Console output levels .
.
.
.
Styling output
Configuring options and generating help .
Routing in shells / CLI
.
Shell API
.
.
.
More topics .
539
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
10 Development
.
.
.
.
.
Configuration .
.
.
.
Routing .
.
.
.
.
.
Sessions .
.
Exceptions .
.
.
.
Error Handling .
.
.
Debugging .
.
.
.
.
Testing .
REST .
.
.
.
.
Dispatcher Filters .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
575
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
11 Deployment
657
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
Check your security .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
.
Set document root .
Update core.php .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
.
.
.
Improve your application’s performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
12 Tutorials & Examples
.
659
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Blog Tutorial
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
Blog Tutorial - Adding a layer
. 673
Simple Authentication and Authorization Application . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Simple Acl controlled Application .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Simple Acl controlled Application - part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
.
.
.
.
.
.
.
.
.
.
.
.
ii
13 Contributing
.
.
.
.
.
.
.
.
Documentation .
.
.
.
.
Tickets .
.
Code .
.
.
.
.
Coding Standards .
.
Backwards Compatibility Guide .
.
CakePHP Development Process
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
14 Appendices
.
2.10 Migration Guide .
.
.
2.9 Migration Guide .
.
.
2.8 Migration Guide .
.
.
2.7 Migration Guide .
.
.
2.6 Migration Guide .
.
.
2.5 Migration Guide .
.
.
2.4 Migration Guide .
.
.
2.3 Migration Guide .
.
.
2.2 Migration Guide .
.
.
2.1 Migration Guide .
2.0 Migration Guide .
.
.
Migration from 1.2 to 1.3 .
.
General Information .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
15 Indices and tables
Index
691
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
719
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
813
815
iii
iv
CHAPTER 1
Getting Started
The CakePHP framework provides a robust base for your application. It can handle every aspect, from the user’s initial
request all the way to the final rendering of a web page. And since the framework follows the principles of MVC, it
allows you to easily customize and extend most aspects of your application.
The framework also provides a basic organizational structure, from filenames to database table names, keeping your
entire application consistent and logical. This concept is simple but powerful. Follow the conventions and you’ll always
know exactly where things are and how they’re organized.
The best way to experience and learn CakePHP is to sit down and build something. To start off we’ll build a simple
blog application.
Blog Tutorial
Welcome to CakePHP. You’re probably checking out this tutorial because you want to learn more about how CakePHP
works. It’s our aim to increase productivity and make coding more enjoyable: we hope you’ll see this as you dive into
the code.
This tutorial will walk you through the creation of a simple blog application. We’ll be getting and installing CakePHP,
creating and configuring a database, and creating enough application logic to list, add, edit, and delete blog posts.
Here’s what you’ll need:
1. A running web server. We’re going to assume you’re using Apache, though the instructions for using other
servers should be very similar. We might have to play a little with the server configuration, but most folks can
get CakePHP up and running without any configuration at all. Make sure you have PHP 5.2.8 or greater.
2. A database server. We’re going to be using MySQL server in this tutorial. You’ll need to know enough about
SQL in order to create a database: CakePHP will be taking the reins from there. Since we’re using MySQL, also
make sure that you have pdo_mysql enabled in PHP.
3. Basic PHP knowledge. The more object-oriented programming you’ve done, the better: but fear not if you’re a
procedural fan.
1
CakePHP Cookbook Documentation, Release 2.x
4. Finally, you’ll need a basic knowledge of the MVC programming pattern. A quick overview can be found in
Understanding Model-View-Controller. Don’t worry, it’s only half a page or so.
Let’s get started!
Getting CakePHP
First, let’s get a copy of fresh CakePHP code.
To get a fresh download, visit the CakePHP project on GitHub: https://github.com/cakephp/cakephp/tags and download
the latest release of 2.0
You can also clone the repository using git4:
git clone -b 2.x git://github.com/cakephp/cakephp.git
Regardless of how you downloaded it, place the code inside of your DocumentRoot. Once finished, your directory
setup should look something like the following:
/path_to_document_root
/app
/lib
/plugins
/vendors
.htaccess
index.php
README
Now might be a good time to learn a bit about how CakePHP’s directory structure works: check out the CakePHP
Folder Structure section.
Tmp directory permissions
Next we’ll need to make the app/tmp directory writable by the webserver. The best way to do this is to find out what
user your webserver runs as. You can run inside any PHP file your webserver
can execute. You should see a username printed. Change the ownership of the app/tmp directory to that user. The
final command you run (in *nix) might look something like this:
$ chown -R www-data app/tmp
If for some reason CakePHP can’t write to that directory, you’ll see warnings and uncaught exceptions that cache data
cannot be written.
4 https://git-scm.com/
2
Chapter 1. Getting Started
CakePHP Cookbook Documentation, Release 2.x
Creating the Blog Database
Next, let’s set up the underlying database for our blog. If you haven’t already done so, create an empty database for use
in this tutorial, with a name of your choice. Right now, we’ll just create a single table to store our posts. We’ll also
throw in a few posts right now to use for testing purposes. Execute the following SQL statements into your database:
/* First, create our posts table: */
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
body TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
/* Then insert some posts for testing: */
INSERT INTO posts (title, body, created)
VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title, body, created)
VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title, body, created)
VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
The choices on table and column names are not arbitrary. If you follow CakePHP’s database naming conventions, and
CakePHP’s class naming conventions (both outlined in CakePHP Conventions), you’ll be able to take advantage of a
lot of free functionality and avoid configuration. CakePHP is flexible enough to accommodate even the worst legacy
database schema, but adhering to convention will save you time.
Check out CakePHP Conventions for more information, but suffice it to say that naming our table ‘posts’ automati-
cally hooks it to our Post model, and having fields called ‘modified’ and ‘created’ will be automagically managed by
CakePHP.
CakePHP Database Configuration
Onward and upward: let’s tell CakePHP where our database is and how to connect to it. For many, this is the first and
last time you configure anything.
A copy of CakePHP’s database configuration file is found in /app/Config/database.php.default. Make a copy
of this file in the same directory, but name it database.php.
The config file should be pretty straightforward: just replace the values in the $default array with those that apply to
your setup. A sample completed configuration array might look something like the following:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => 'cakeBlog',
'password' => 'c4k3-rUl3Z',
'database' => 'cake_blog_tutorial',
'schema' => '',
'prefix' => '',
'encoding' => 'utf8'
);
Blog Tutorial
3
CakePHP Cookbook Documentation, Release 2.x
Once you’ve saved your new database.php file, you should be able to open your browser and see the CakePHP
welcome page. It should also tell you that your database connection file was found, and that CakePHP can successfully
connect to the database.
Note: Remember that you’ll need to have PDO, and pdo_mysql enabled in your php.ini.
Optional Configuration
There are a few other items that can be configured. Most developers complete these laundry-list items, but they’re not
required for this tutorial. One is defining a custom string (or “salt”) for use in security hashes. The second is defining
a custom number (or “seed”) for use in encryption.
The security salt is used for generating hashes. Change the default Security.salt value in /app/Config/core.php.
The replacement value should be long, hard to guess and be as random as you can make it:
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'pl345e-P45s_7h3*S@l7!');
The cipher seed is used for encrypt/decrypt strings. Change the default Security.cipherSeed value by editing
/app/Config/core.php. The replacement value should be a large random integer:
/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
Configure::write('Security.cipherSeed', '7485712659625147843639846751');
A Note on mod_rewrite
Occasionally new users will run into mod_rewrite issues. For example if the CakePHP welcome page looks a little
funny (no images or CSS styles), it probably means mod_rewrite is not functioning on your system. Please refer to one
of the sections below about URL rewriting for your webserver to get you up and running:
URL Rewriting
Apache and mod_rewrite (and .htaccess)
While CakePHP is built to work with mod_rewrite out of the box–and usually does–we’ve noticed that a few users
struggle with getting everything to play nicely on their systems.
Here are a few things you might try to get it running correctly. First look at your httpd.conf. (Make sure you are editing
the system httpd.conf rather than a user- or site-specific httpd.conf.)
These files can vary between different distributions and Apache versions. You may also take a look at https://wiki.
apache.org/httpd/DistrosDefaultLayout for further information.
1. Make sure that an .htaccess override is allowed and that AllowOverride is set to All for the correct DocumentRoot.
You should see something similar to:
4
Chapter 1. Getting Started
CakePHP Cookbook Documentation, Release 2.x
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
Id | Title | Created |
---|---|---|
Html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?> |
Created:
Verify that this is working by trying the links at /posts/index or manually requesting a post by accessing /posts/ view/1. Adding Posts Reading from the database and showing us the posts is a great start, but let’s allow for adding new posts. First, start by creating an add() action in the PostsController: class PostsController extends AppController { public $helpers = array('Html', 'Form', 'Flash'); public $components = array('Flash'); public function index() { $this->set('posts', $this->Post->find('all')); } public function view($id) { if (!$id) { throw new NotFoundException(__('Invalid post')); } $post = $this->Post->findById($id); Blog Tutorial - Adding a layer (continues on next page) 13 CakePHP Cookbook Documentation, Release 2.x (continued from previous page) if (!$post) { throw new NotFoundException(__('Invalid post')); } $this->set('post', $post); } public function add() { if ($this->request->is('post')) { $this->Post->create(); if ($this->Post->save($this->request->data)) { $this->Flash->success(__('Your post has been saved.')); return $this->redirect(array('action' => 'index')); } $this->Flash->error(__('Unable to add your post.')); } } } $this->request->is() takes a single argument, which can be the request METHOD (get, put, post, It is not a way to check for specific posted data. For instance, Note: delete) or some request identifier (ajax). $this->request->is('book') will not return true if book data was posted. Note: You need to include the FlashComponent - and FlashHelper - in any controller where you will use it. necessary, include it in your AppController. If Here’s what the add() action does: if the HTTP method of the request was POST, it tries to save the data using the Post model. If for some reason it doesn’t save, it just renders the view. This gives us a chance to show the user validation errors or other warnings. Every CakePHP request includes a CakeRequest object which is accessible using $this->request. The request object contains useful information regarding the request that was just received, and can be used to control the flow of your application. In this case, we use the CakeRequest::is() method to check that the request is a HTTP POST request. When a user uses a form to POST data to your application, that information is available in $this->request->data. You can use the pr() or debug() functions to print it out if you want to see what it looks like. We use the FlashComponent’s FlashComponent::success() method to set a message to a session variable to be displayed on the page after redirection. In the layout we have FlashHelper::render() which displays the message and clears the corresponding session variable. The controller’s Controller::redirect function redirects to another URL. The param array('action' => 'index') translates to URL /posts (that is, the index action of the posts controller). You can refer to Router::url() function on the API10 to see the formats in which you can specify a URL for various CakePHP functions. Calling the save() method will check for validation errors and abort the save if any occur. We’ll discuss how those errors are handled in the following sections. We call the create() method first in order to reset the model state for saving new information. It does not actually create a record in the database, but clears Model::$id and sets Model::$data based on your database field defaults. 10 https://api.cakephp.org 14 Chapter 1. Getting Started CakePHP Cookbook Documentation, Release 2.x Data Validation CakePHP goes a long way toward taking the monotony out of form input validation. Everyone hates coding up endless forms and their validation routines. CakePHP makes it easier and faster. To take advantage of the validation features, you’ll need to use CakePHP’s FormHelper in your views. The FormHelper is available by default to all views at $this->Form. Here’s our add view: