What Is New in CakePHP 3.0 (Summary)
CakePHP 3.0 is a major overhaul focused on modern PHP practices and increased flexibility. The core changes revolve around adopting namespaces, a new, more powerful ORM, and separated components for better reuse. This foundation makes the framework more decoupled and developer-friendly.
| Category | Key Changes |
|---|---|
| New Features | PSR-4 namespaces, New ORM (Table/Entity), Stand-alone Components (Http, Database), Improved Flexibility |
| Improvements | Better Static Analysis, Enhanced Code Generation (Bake), Simplified Configuration, New Folder Structure |
| Deprecated / Removed | Old 1.x/2.x APIs, Magic Properties (model->read()), Sanitize Class, Legacy Components |
| Breaking Changes | Namespace for all classes, New method signatures, Different routing defaults, Updated template syntax (.ctp) |
Why Did CakePHP 3.0 Switch to Namespaces?
Namespaces were introduced to organize code and avoid class name collisions. Every core class and your application classes now live under a namespace, like App\Controller\ArticlesController. This aligns CakePHP with modern PHP standards and improves autoloading.
In practice, this means you must update all your class declarations and use statements. The old App::uses() method is gone. This change makes the codebase cleaner and works better with IDE tools and Composer.
How Does the New ORM Work?
The Object-Relational Mapping (ORM) layer was completely rewritten for clarity and power. It splits the data layer into Table and Entity objects. The Table class handles queries and business logic, while Entity represents a single row of data.
Key ORM Changes
- New method names:
find(),save(),delete()replace older magic methods. - Query objects are now immutable and use a fluent interface for building complex finds.
- Associations are defined as properties on Table classes, making them more explicit.
- Behaviors attach to Table objects, not models, and use callable arrays.
What Happened to Controllers and Views?
Controllers lost several magic properties and methods. The $modelClass property is determined by the controller name, and the loadModel() method is used explicitly. View rendering is more straightforward, with the View class becoming a standalone component.
Template files (.ctp) require updated syntax. The old $this->ModelName->field is replaced with $entity->field. Helpers also follow new conventions, and the View block API ($this->fetch()) is the standard for layout blocks.
Are Routing and Configuration Different Now?
Yes, routing defaults changed. The extension parsing is disabled by default, and routes no longer automatically include the plugin, controller, and action keys in pass array. You must define these explicitly if needed.
Configuration files moved from app/Config/ to config/. The database.php config uses a new structure, and the core.php file is gone. Environment variables are encouraged for sensitive data.
FAQ
Is my CakePHP 2.x app broken if I upgrade to 3.0?
Yes, it's a breaking major release. You cannot simply replace files. A full migration is required, rewriting controllers, models, and views to use the new namespaces, ORM, and APIs.
What happened to the Sanitize component?
It was removed. You should rely on proper data binding with the ORM's entity layer or use the HtmlPurifier library for cleaning HTML input. The framework now encourages context-specific escaping in templates.
How do I perform a simple find('list') in 3.0?
Use the new query builder. For example: $articles = $this->Articles->find('list')->toArray();. The find() method now returns a Query object that you can configure before executing.
Can I still use my old custom datasources and behaviors?
They need to be rewritten. Datasources now implement the new Cake\Database\Driver interface, and behaviors attach to Table objects with different method signatures. The plugin system also changed with namespaces.
Why are my form fields not populating data automatically?
The FormHelper in 3.0 uses the context provided by the Form class. Ensure your controller passes an entity to the view and that the form uses the correct entity for data binding. Magic property access ($this->request->data) is less prevalent.