Documentation
Book
API
Videos
Reporting Security Issues
Privacy Policy
Logos & Trademarks
Business Solutions
Swag
Road Trip
Team
Community
Community
Get Involved
Issues (Github)
Bakery
Featured Resources
Training
Meetups
My CakePHP
CakeFest
Newsletter
Linkedin
YouTube
Facebook
Twitter
Help & Support
Forum
Stack Overflow
IRC
Slack
Paid Support
B
CakePHP 3.9 Red Velvet
Cookbook
A
Language:
en
pt
es
ja
fr
zh
tr
ru
Version:
3.x
4.x Book
3.x Book
2.x Book
1.3 Book
1.2 Book
1.1 Book
Nav
Table of Contents
×
Improve This Doc
Contents
¶
Preface
CakePHP at a Glance
Conventions Over Configuration
The Model Layer
The View Layer
The Controller Layer
CakePHP Request Cycle
Just the Start
Additional Reading
Where to Get Help
CakePHP Conventions
CakePHP Folder Structure
Quick Start Guide
Content Management Tutorial
Getting CakePHP
Checking our Installation
CMS Tutorial - Creating the Database
Database Configuration
Creating our First Model
CMS Tutorial - Creating the Articles Controller
Create the Article List Template
Create the View Action
Create the View Template
Adding Articles
Create Add Template
Adding Simple Slug Generation
Add Edit Action
Create Edit Template
Update Validation Rules for Articles
Add Delete Action
3.x Migration Guide
3.9 Migration Guide
3.9 Migration Guide
3.8 Migration Guide
3.8 Migration Guide
3.7 Migration Guide
3.7 Migration Guide
3.6 Migration Guide
3.6 Migration Guide
3.5 Migration Guide
3.5 Migration Guide
3.4 Migration Guide
3.4 Migration Guide
3.3 Migration Guide
3.3 Migration Guide
3.2 Migration Guide
3.2 Migration Guide
3.1 Migration Guide
3.1 Migration Guide
3.0 Migration Guide
3.0 Migration Guide
New ORM Upgrade Guide
Tutorials & Examples
Content Management Tutorial
Getting CakePHP
Checking our Installation
CMS Tutorial - Creating the Database
Database Configuration
Creating our First Model
CMS Tutorial - Creating the Articles Controller
Create the Article List Template
Create the View Action
Create the View Template
Adding Articles
Create Add Template
Adding Simple Slug Generation
Add Edit Action
Create Edit Template
Update Validation Rules for Articles
Add Delete Action
CMS Tutorial - Tags and Users
Adding Tagging to Articles
Updating Articles to Enable Tagging
Finding Articles By Tags
Improving the Tagging Experience
Auto-populating the Tag String
CMS Tutorial - Authentication
Adding Password Hashing
Contributing
Documentation
Translations
Documentation Formatting Guide
Tickets
Reporting Bugs
Reporting Security Issues
Code
Initial Setup
Working on a Patch
Submitting a Pull Request
Coding Standards
Adding New Features
IDE Setup
Indentation
Line Length
Control Structures
Comparison
Function Calls
Method Definition
Bail Early
Method Chaining
Commenting Code
Including Files
PHP Tags
Naming Convention
Careful when using empty()/isset()
Backwards Compatibility Guide
Migration Guides
Using CakePHP
Working on CakePHP
Deprecations
Getting Started
Installation
Installing CakePHP
Installing Composer
Create a CakePHP Project
Keeping Up To Date with the Latest CakePHP Changes
Installation using Oven
Permissions
Development Server
Production
Fire It Up
URL Rewriting
Apache
nginx
IIS7 (Windows hosts)
I Can’t Use URL Rewriting
Configuration
Configuring your Application
Loading Additional Configuration Files
Environment Variables
General Configuration
Using a CDN
Database Configuration
Caching Configuration
Error and Exception Handling Configuration
Logging Configuration
Email Configuration
Session Configuration
Routing configuration
Additional Class Paths
Plugin, View Template and Locale Paths
Inflection Configuration
Configure Class
Writing Configuration data
Reading Configuration Data
Checking to see if Configuration Data is Defined
Deleting Configuration Data
Reading & Deleting Configuration Data
Reading and writing configuration files
Loading Configuration Files
Creating or Modifying Configuration Files
Storing Runtime Configuration
Restoring Runtime Configuration
Configuration Engines
Bootstrapping CakePHP
Application::bootstrap()
Disabling Generic Tables
Application
Adding the new HTTP Stack to an Existing Application
Routing
Quick Tour
Connecting Routes
Route Elements
Reserved Route Elements
Configuring Route Options
Passing Parameters to Action
Using Named Routes
Prefix Routing
Creating Links to Prefix Routes
Plugin Routing
Creating Links to Plugin Routes
SEO-Friendly Routing
Matching Specific HTTP Methods
Matching Specific Hostnames
Routing File Extensions
Connecting Scoped Middleware
Grouping Middleware
RESTful Routing
Creating Nested Resource Routes
Limiting the Routes Created
Changing the Controller Actions Used
Mapping Additional Resource Routes
Custom Route Classes for Resource Routes
URL Inflection for Resource Routes
Changing the Path Element
Passed Arguments
Generating URLs
Redirect Routing
Entity Routing
Custom Route Classes
Default Route Class
Fallbacks Method
Creating Persistent URL Parameters
Handling Named Parameters in URLs
Dispatcher Filters
Request & Response Objects
Request
Request Parameters
Query String Parameters
Request Body Data
File Uploads
PUT, PATCH or DELETE Data
Environment Variables (from $_SERVER and $_ENV)
XML or JSON Data
Path Information
Checking Request Conditions
Session Data
Host and Domain Name
Reading the HTTP Method
Restricting Which HTTP method an Action Accepts
Reading HTTP Headers
Trusting Proxy Headers
Checking Accept Headers
Cookies
Response
Dealing with Content Types
Sending Files
Sending a String as File
Setting Headers
Setting the Body
Setting the Character Set
Interacting with Browser Caching
Fine Tuning HTTP Cache
Setting Cookies
Setting Cross Origin Request Headers (CORS)
Common Mistakes with Immutable Responses
Cookie Collections
Creating Cookies
Reading Cookies
Middleware
Middleware in CakePHP
Using Middleware
Adding Middleware from Plugins
PSR-7 Requests and Responses
Interacting with Requests
Interacting with Responses
Creating Middleware
Routing Middleware
Content Security Policy Header Middleware
Security Header Middleware
Encrypted Cookie Middleware
Cross Site Request Forgery (CSRF) Middleware
Integration with FormHelper
CSRF Protection and AJAX Requests
Body Parser Middleware
Controllers
The App Controller
Request Flow
Controller Actions
Interacting with Views
Setting View Variables
Setting View Options
Rendering a View
Redirecting to Other Pages
Redirecting to Another Action on the Same Controller
Loading Additional Models
Paginating a Model
Configuring Components to Load
Configuring Helpers to Load
Request Life-cycle Callbacks
Event List
Controller Callback Methods
More on Controllers
The Pages Controller
Components
Views
The App View
View Templates
Alternative Echos
Alternative Control Structures
View Variables
Setting View Variables
Extending Views
Using View Blocks
Displaying Blocks
Using Blocks for Script and CSS Files
Layouts
Using Layouts from Plugins
Elements
Passing Variables into an Element
Caching Elements
Requesting Elements from a Plugin
Routing prefix and Elements
Caching Sections of Your View
View Events
Event List
Creating Your Own View Classes
More About Views
View Cells
Themes
JSON and XML views
Helpers
Database Access & ORM
Quick Example
More Information
Database Basics
Query Builder
Table Objects
Entities
Retrieving Data & Results Sets
Validating Data
Saving Data
Deleting Data
Associations - Linking Tables Together
Behaviors
Schema System
Schema Cache Shell
Using CakePHP
Caching
Configuring Cache Engines
Engine Options
FileEngine Options
RedisEngine Options
MemcacheEngine Options
Configuring Cache Fallbacks
Removing Configured Cache Engines
Writing to a Cache
Writing Multiple Keys at Once
Read Through Caching
Reading From a Cache
Reading Multiple Keys at Once
Deleting From a Cache
Deleting Multiple Keys at Once
Clearing Cached Data
Using Cache to Store Counters
Using Cache to Store Common Query Results
Using Groups
Globally Enable or Disable Cache
Creating a Cache Engine
Console Tools, Shells & Tasks
The CakePHP Console
Console Applications
Renaming Commands
Commands
Console Commands
Command Input/Output
Option Parsers
Shell Helpers
Running Shells as Cron Jobs
CakePHP Provided Commands
Cache Shell
I18N Shell
Completion Shell
Plugin Shell
Routes Shell
Schema Cache Shell
Server Shell
Upgrade Shell
Shells
Interactive Console (REPL)
Routing in the Console Environment
Debugging
Basic Debugging
Using the Debugger Class
Outputting Values
Masking Data
Logging With Stack Traces
Generating Stack Traces
Getting an Excerpt From a File
Using Logging to Debug
Debug Kit
Deployment
Moving files
Adjust config/app.php
Check Your Security
Set Document Root
Improve Your Application’s Performance
Deploying an update
Email
Basic Usage
Choosing the Sender
Configuration
Configuring Transports
Configuration Profiles
Setting Headers
Sending Templated Emails
Sending Attachments
Using Transports
Creating Custom Transports
Relaxing Address Validation Rules
Sending Messages Quickly
Sending Emails from CLI
Creating Reusable Emails
Testing Email
Assertion methods
Error & Exception Handling
Error & Exception Configuration
Changing Exception Handling
Customize Error Templates
Customize the Error Page Layout
Customize the ErrorController
Change the ExceptionRenderer
Changing the ErrorController Class
Creating your Own Error Handler
Changing Fatal Error Behavior
Creating your own Application Exceptions
Logging Exceptions
Built in Exceptions for CakePHP
HTTP Exceptions
Using HTTP Exceptions in your Controllers
Other Built In Exceptions
Events System
Example Event Usage
Accessing Event Managers
Global Event Manager
Tracking Events
Core Events
Registering Listeners
Registering Anonymous Listeners
Interacting with Existing Listeners
Establishing Priorities
Getting Event Data as Function Parameters
Dispatching Events
Stopping Events
Getting Event Results
Removing Callbacks and Listeners
Additional Reading
Internationalization & Localization
Setting Up Translations
Language Files
Extract Pot Files with I18n Shell
Setting the Default Locale
Changing the Locale at Runtime
Using Translation Functions
Using Variables in Translation Messages
Plurals
Creating Your Own Translators
Creating Message Parsers
Creating Generic Translators
Plurals and Context in Custom Translators
Using Different Formatters
Localizing Dates and Numbers
Parsing Localized Datetime Data
Automatically Choosing the Locale Based on Request Data
Logging
Logging Configuration
Creating Log Adapters
Error and Exception Logging
Interacting with Log Streams
Using the FileLog Adapter
Logging to Syslog
Writing to Logs
Using Levels
Logging Scopes
Log API
Convenience Methods
Logging Trait
Using Monolog
Modelless Forms
Creating a Form
Setting Form Values
Getting Form Values
Processing Request Data
Getting Form Errors
Invalidating Individual Form Fields from Controller
Creating HTML with FormHelper
Pagination
Basic Usage
Advanced Usage
Simple Pagination
Using the PaginatorComponent Directly
Paginating Multiple Queries
Paginating the Same Model multiple Times
Control which Fields Used for Ordering
Limit the Maximum Number of Rows per Page
Joining Additional Associations
Out of Range Page Requests
Pagination in the View
Plugins
Installing a Plugin With Composer
Manually Installing a Plugin
Manually Autoloading Plugin Classes
Loading a Plugin
Plugin Hook Configuration
Old Style Plugins
Using Plugin Classes
Creating Your Own Plugins
Creating a Plugin Using Bake
Plugin Objects
Plugin Routes
Plugin Controllers
Plugin Models
Plugin Templates
Overriding Plugin Templates from Inside Your Application
Plugin Assets
Linking to Assets in Plugins
Components, Helpers and Behaviors
Commands
Testing your Plugin
Publishing your Plugin
Plugin Map File
Manage Your Plugins using Mixer
REST
The Simple Setup
Accepting Input in Other Formats
RESTful Routing
Security
Security Utility
Encrypting and Decrypting Data
Hashing Data
Getting Secure Random Data
Cross Site Request Forgery
Using the CsrfComponent
Integration with FormHelper
CSRF Protection and AJAX Requests
Disabling the CSRF Component for Specific Actions
Security Component
Handling Blackhole Callbacks
Restrict Actions to SSL
Restricting Cross Controller Communication
Form Tampering Prevention
Usage
CSRF Protection
Disabling Security Component for Specific Actions
Sessions
Session Configuration
Built-in Session Handlers & Configuration
Session Handlers
Database Sessions
Cache Sessions
Setting ini directives
Creating a Custom Session Handler
Accessing the Session Object
Reading & Writing Session Data
Destroying the Session
Rotating Session Identifiers
Flash Messages
Testing
Installing PHPUnit
Install PHPUnit with Composer
Using the PHAR File
Test Database Setup
Checking the Test Setup
Test Case Conventions
Creating Your First Test Case
Running Tests
Filtering Test Cases
Generating Code Coverage
Combining Test Suites for Plugins
Test Case Lifecycle Callbacks
Fixtures
Test Connections
PHPUnit Configuration
Creating Fixtures
Dynamic Data and Fixtures
Importing Table Information
Loading Fixtures in your Test Cases
Fixture Factories
Testing Table Classes
Creating a Test Method
Mocking Model Methods
Controller Integration Testing
Setting up the Request
Testing Actions That Require Authentication
Testing Stateless Authentication and APIs
Testing Actions Protected by CsrfComponent or SecurityComponent
Integration Testing PSR-7 Middleware
Testing with Encrypted Cookies
Testing Flash Messages
Testing a JSON Responding Controller
Disabling Error Handling Middleware in Tests
Assertion methods
Comparing test results to a file
Console Integration Testing
Testing Views
Testing Components
Testing Helpers
Testing Events
Testing Email
Creating Test Suites
Creating Tests for Plugins
Generating Tests with Bake
Integration with Jenkins
Create a Job
Add Test Database Config
Add your Tests
Run a Build
Validation
Creating Validators
Requiring Field Presence
Allowing Empty Fields
Adding Validation Rules
Using Custom Validation Rules
Conditional/Dynamic Error Messages
Conditional Validation
Marking Rules as the Last to Run
Adding Validation Providers
Nesting Validators
Creating Reusable Validators
Validating Data
Validating Entity Data
Core Validation Rules
Utility Classes
App Class
Finding Classes
Finding Paths to Namespaces
Locating Plugins
Locating Themes
Loading Vendor Files
Collections
Quick Example
List of Methods
Iterating
Filtering
Aggregation
Grouping and Counting
Sorting
Working with Tree Data
Other Methods
Withdrawing Elements
Expanding Collections
Modifiying Elements
Making Collection Methods Reusable
Optimizing Collections
Making Collections Rewindable
Cloning Collections
Folder & File
Basic Usage
Folder API
File API
Hash
Hash Path Syntax
Expression Types
Attribute Matching Types
Http Client
Doing Requests
Creating Multipart Requests with Files
Building Multipart Request Bodies by Hand
Sending Request Bodies
Request Method Options
Authentication
Using Basic Authentication
Using Digest Authentication
OAuth 1 Authentication
OAuth 2 Authentication
Proxy Authentication
Creating Scoped Clients
Setting and Managing Cookies
Response Objects
Reading Response Bodies
Reading JSON and XML Response Bodies
Accessing Response Headers
Accessing Cookie Data
Checking the Status Code
Changing Transport Adapters
Inflector
Summary of Inflector Methods and Their Output
Creating Plural & Singular Forms
Creating CamelCase and under_scored Forms
Creating Human Readable Forms
Creating Table and Class Name Forms
Creating Variable Names
Creating URL Safe Strings
Inflection Configuration
Loading Custom Inflections
Number
Formatting Currency Values
Setting the Default Currency
Formatting Floating Point Numbers
Formatting Percentages
Interacting with Human Readable Values
Formatting Numbers
Format Differences
Configure formatters
Registry Objects
Loading Objects
Triggering Callbacks
Disabling Callbacks
Text
Convert Strings into ASCII
Creating URL Safe Strings
Generating UUIDs
Simple String Parsing
Formatting Strings
Wrapping Text
Highlighting Substrings
Removing Links
Truncating Text
Truncating the Tail of a String
Extracting an Excerpt
Converting an Array to Sentence Form
Date & Time
Creating Time Instances
Manipulation
Formatting
Setting the Default Locale and Format String
Formatting Relative Times
Conversion
Comparing With the Present
Comparing With Intervals
Dates
Immutable Dates and Times
Accepting Localized Request Data
Supported Timezones
Xml
Loading XML documents
Loading HTML documents
Transforming a XML String in Array
Transforming an Array into a String of XML
Using Namespaces
Creating a Child
Plugins
Authorization
Authentication
Bake
Chronos
Debug Kit
Migrations
Elasticsearch
Upgrade Tool
Installation
Usage
Other
Constants & Functions
Global Functions
Core Definition Constants
Timing Definition Constants
Appendices
3.x Migration Guide
3.x Migration Guide
Forwards Compatibility Shimming
General Information
CakePHP Development Process
Glossary
Phinx
Phinx
Welcome
→
Follow @CakePHP