New in CakePHP 3
New in cakephp3
March 22, 2015
3.0.0 is released
Frequent Releases
Bugfixes every 2-4 weeks
PHP 5.4 +
Soon to be PHP 5.5+
All the PSRs
Zero through Four
Clean up
Rabid conventions removed.
Standalone
Components
We have a few.
I18n
// Message formatting
echo __("Hello, my name is {0}, I'm {1} years old",
['Sara', 12]);
>>> Hello, my name is Sara, I’m 12 years old
// Decimals and integers
echo __('You have traveled {0,number,decimal}
kilometers in {1,number,integer} weeks',
[5423.344, 5.1]);
>>> You have traveled 5,423.34 kilometers in 5 weeks
Messages
echo __('{0,plural,
=0{No records found}
=1{Found 1 record}
other{Found # records}}',
[1]);
>>> Found 1 record
// Simpler message ids.
echo __('records.found', [1]);
>>> Found 1 record
Plurals
msgid "One file removed"
msgid_plural "{0} files removed"
msgstr[0] "jednom datotekom je uklonjen"
msgstr[1] "{0} datoteke uklonjenih"
msgstr[2] "{0} slika uklonjenih"
Catalog Files
use CakeI18nTime;
use CakeI18nNumber;
$date = new Time('2015-04-05 23:00:00');
echo $date;
>>> 05/04/2015 23:00
echo Number::format(524.23);
>>> 524.23
Numbers & Dates
Locale::setDefault(‘fr-FR’);
$date = new Time('2015-04-05 23:00:00');
echo $date;
>>> 5 avril 2015 23:00:00 UTC
echo Number::format(524.23);
>>> 524,23
Numbers & Dates
Use Alone
Use the i18n libs anywhere with composer.
Routing
Router::scope(‘/u‘, function ($routes) {
$routes->connect(‘/name/:username’, [‘controller’ => ‘Users’, ’action’ => ‘show’]);
});
// Use namespace prefixed controllers.
Router::prefix(‘admin’, function ($routes) {
$routes->connect(‘/articles/:action’, [‘controller’ => ‘Articles’]);
});
Routing Scopes
// Classic array format.
echo $this->Url->build([
‘controller’ => ‘Users’,
‘action’ => ‘show’,
‘username’ => ‘thewoz’
]);
>>> /u/name/thewoz
echo $this->Url->build([
‘prefix’ => ‘Admin’,
‘controller’ => ‘Articles’,
‘action’ => ‘index’
]);
>>> /admin/articles/index
Reverse Routing
Router::scope(‘/u‘, function ($routes) {
// Explicit name
$routes->connect(‘/friends’, [‘controller’ => ‘Friends’], [‘_name’ => ‘u:friends’]);
});
echo $this->Url->build([‘_name’ => ‘u:friends’]);
>>> /u/friends
Named Routes
Router::scope('/', function ($routes) {
$routes->extensions(['json']);
$routes->resources('Articles');
});
>>> /articles and /articles/:id are now connected.
// Generate nested resources
Router::scope('/', function ($routes) {
$routes->extensions([‘json’]);
$routes->resources('Articles', function ($routes) {
$routes->resources('Comments');
});
});
>>> /articles/:article_id/comments is now connected.
Resource Routing
Collections
Jose Lorenzo
Rodriguez
Iterator Master
Immutable
Mutator methods make new collections.
$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);
// Create a new collection containing elements
// with a value greater than one.
$big = $collection->filter(function ($value, $key, $iterator) {
return $value > 1;
});
// Search data in memory. match() makes a new iterator
$collection = new Collection($comments);
$commentsFromMark = $collection->match(['user.name' => 'Mark']);
Improved Arrays
$people = new Collection($peopleData);
// Find all the non-blondes
$notBlond = $people->reject(function ($p) {
return $p->hair_colour === ‘blond’;
});
// Get all the people named jose
$joses = $notBlond->filter(function ($p) {
return strtolower($p->first_name) === ‘jose’;
});
// Count by their hair colour
$counts = $joses->countBy(function ($p) {
return $p->hair_colour;
});
Pipeline Example
class JoseFinder {
public function __invoke($person) {
return strtolower($person->first_name) === ‘jose’;
}
}
$joses = $people->filter(new JoseFinder());
$notBlond = $people->reject(new NotBlondFilter());
Pipeline ++
Use Alone
Collections can be used in any project.
ORM
It is not 2005
anymore
ActiveRecord Datamapper
// Get a table gateway/mapper.
$connection = ConnectionManager::get(‘default’);
$articles = new ArticlesTable([‘connection’ => $connection]);
// Basic query building
$query = $articles->find()
->where([‘Articles.author_id’ => $userid])
->order([‘Articles.created’ => ‘DESC’]);
// Find some published, promoted articles
$query = $articles->find(‘promoted’)
->find(‘published’);
Finding Records
// Find articles and eager load relations (1 query)
$query = $articles->find()
->contain([‘Authors’, ‘Categories’]);
// Load deeply nested relations (2 queries)
$query = $articles->find()
->contain([‘Authors.RecentActivities’]);
Eager Loading
// Find all the articles tagged with ‘Cat’
$query = $articles->find()->matching(‘Tags’, function ($q) {
return $q->where([‘Tags.name’ => ‘Cat’]);
});
// Find all the articles without the tag ‘Cat’
$query = $articles->find()->notMatching(‘Tags’, function ($q) {
return $q->where([‘Tags.name’ => ‘Cat’]);
});
Matching
// Do extraction and transformations
$result = $articles->find()
->all()
->extract(‘title’)
->map(function ($item) { return strtoupper($item); });
// Extract and reduce
$query = $articles->find()->contain([‘Tags’]);
$uniqueTags = $articles->all()
->extract(‘tags.{*}.name’)
->reduce(function ($out, $tag) {
if (!in_array($tag, $out) {
$out[] = $tag;
}
return $out;
}, []);
Collections+
Entities
Just vanilla PHP objects for the most part.
namespace AppModelEntity;
use CakeORMEntity;
class Article extends Entity
{
protected $_accessible = [‘title’, ‘body’, ‘author_id’];
}
Article Entity
namespace AppModelEntity;
use CakeORMEntity;
class User extends Entity
{
protected function _getFullName()
{
return $this->_properties['first_name'] . ' ' .
$this->_properties['last_name'];
}
}
echo $user->full_name;
Virtual Fields
Inspired By
SQLAlchemy
The best ORM I’ve ever used.
No Proxies,
No Annotations,
No Identity Map,
No Runtime Reflection
No Lazy Loading
Use alone
Use the ORM anywhere with composer.
What’s Next?
What’s Next
• New DateTime library, replacing Carbon
• Polymorphic Associations
• PSR7 Support
• Value Objects
Thank You.
https://joind.in/14774
Twitter - mark_story
Github - markstory

More Related Content

PDF
Future of HTTP in CakePHP
PDF
Advanced Querying with CakePHP 3
PDF
Agile database access with CakePHP 3
PDF
CakeFest 2013 keynote
PDF
The Origin of Lithium
PDF
The Zen of Lithium
PDF
Lithium: The Framework for People Who Hate Frameworks
KEY
Php 101: PDO
Future of HTTP in CakePHP
Advanced Querying with CakePHP 3
Agile database access with CakePHP 3
CakeFest 2013 keynote
The Origin of Lithium
The Zen of Lithium
Lithium: The Framework for People Who Hate Frameworks
Php 101: PDO

What's hot (20)

PDF
Dependency Injection IPC 201
PDF
PHP Data Objects
PDF
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
PDF
Internationalizing CakePHP Applications
PDF
Building Lithium Apps
PDF
PHP 5.3 and Lithium: the most rad php framework
PDF
The State of Lithium
PDF
News of the Symfony2 World
PDF
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
PPT
Quebec pdo
KEY
Introducing CakeEntity
PDF
Symfony2 - WebExpo 2010
KEY
Introducing CakeEntity
PDF
Dependency Injection
PDF
Unit and Functional Testing with Symfony2
PDF
Php unit the-mostunknownparts
PPT
Corephpcomponentpresentation 1211425966721657-8
KEY
Lithium Best
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
Doctrine MongoDB ODM (PDXPHP)
Dependency Injection IPC 201
PHP Data Objects
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Internationalizing CakePHP Applications
Building Lithium Apps
PHP 5.3 and Lithium: the most rad php framework
The State of Lithium
News of the Symfony2 World
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Quebec pdo
Introducing CakeEntity
Symfony2 - WebExpo 2010
Introducing CakeEntity
Dependency Injection
Unit and Functional Testing with Symfony2
Php unit the-mostunknownparts
Corephpcomponentpresentation 1211425966721657-8
Lithium Best
international PHP2011_Bastian Feder_jQuery's Secrets
Doctrine MongoDB ODM (PDXPHP)
Ad

Similar to New in cakephp3 (20)

PPT
Synapseindia reviews sharing intro cakephp
PPTX
Cake PHP 3 Presentaion
PDF
CakePHP
PPTX
Ei cakephp
PPTX
Cakeph pppt
PPTX
PPT
Language literacy
PPT
Lecture n
PDF
cake phptutorial
PDF
CakePHP 3.0: Embracing the future
PDF
Using and reusing CakePHP plugins
PDF
CakePHP Fundamentals - 1.2 @ OCPHP
DOCX
Laravel
PDF
Ch ch-changes cake php2
PPT
Recursive in CakePHP
PDF
Awesome Tools 2017
PDF
4 introduction-php-mvc-cakephp-m4-controllers-slides
PDF
How else can you write the code in PHP?
KEY
Can't Miss Features of PHP 5.3 and 5.4
PDF
Laravel tips-2019-04
Synapseindia reviews sharing intro cakephp
Cake PHP 3 Presentaion
CakePHP
Ei cakephp
Cakeph pppt
Language literacy
Lecture n
cake phptutorial
CakePHP 3.0: Embracing the future
Using and reusing CakePHP plugins
CakePHP Fundamentals - 1.2 @ OCPHP
Laravel
Ch ch-changes cake php2
Recursive in CakePHP
Awesome Tools 2017
4 introduction-php-mvc-cakephp-m4-controllers-slides
How else can you write the code in PHP?
Can't Miss Features of PHP 5.3 and 5.4
Laravel tips-2019-04
Ad

More from markstory (20)

PDF
Dependency injection in CakePHP
PDF
Safer, More Helpful CakePHP
PDF
CakePHP - The Road Ahead
PDF
CakePHP mistakes made 2015
PDF
PHP WTF
PDF
CakePHP 3.0 and beyond
PDF
CakePHP mistakes made confoo 2015
PDF
CakePHP mistakes made
PDF
Performance and optimization CakeFest 2014
PDF
Road to CakePHP 3.0
PDF
Performance and optimization
PDF
OWASP Top 10 2013
PDF
CakePHP the yum & yuck
PDF
Introduction to Twig
PDF
Owasp top 10
PDF
Simple search with elastic search
PDF
Making the most of 2.2
PDF
Intro to continuous integration
PDF
Evented applications with RabbitMQ and CakePHP
PDF
PHPunit and you
Dependency injection in CakePHP
Safer, More Helpful CakePHP
CakePHP - The Road Ahead
CakePHP mistakes made 2015
PHP WTF
CakePHP 3.0 and beyond
CakePHP mistakes made confoo 2015
CakePHP mistakes made
Performance and optimization CakeFest 2014
Road to CakePHP 3.0
Performance and optimization
OWASP Top 10 2013
CakePHP the yum & yuck
Introduction to Twig
Owasp top 10
Simple search with elastic search
Making the most of 2.2
Intro to continuous integration
Evented applications with RabbitMQ and CakePHP
PHPunit and you

Recently uploaded (20)

PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
PPTX
Computer Software - Technology and Livelihood Education
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
Guide to Food Delivery App Development.pdf
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
Visual explanation of Dijkstra's Algorithm using Python
PPTX
Python is a high-level, interpreted programming language
PDF
AI Guide for Business Growth - Arna Softech
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Microsoft Office 365 Crack Download Free
PDF
Workplace Software and Skills - OpenStax
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Internet Download Manager IDM Crack powerful download accelerator New Version...
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
Computer Software - Technology and Livelihood Education
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Topaz Photo AI Crack New Download (Latest 2025)
Practical Indispensable Project Management Tips for Delivering Successful Exp...
Full-Stack Developer Courses That Actually Land You Jobs
Guide to Food Delivery App Development.pdf
Matchmaking for JVMs: How to Pick the Perfect GC Partner
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Visual explanation of Dijkstra's Algorithm using Python
Python is a high-level, interpreted programming language
AI Guide for Business Growth - Arna Softech
CCleaner 6.39.11548 Crack 2025 License Key
Microsoft Office 365 Crack Download Free
Workplace Software and Skills - OpenStax
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)

New in cakephp3

  • 3. March 22, 2015 3.0.0 is released
  • 5. PHP 5.4 + Soon to be PHP 5.5+
  • 6. All the PSRs Zero through Four
  • 10. // Message formatting echo __("Hello, my name is {0}, I'm {1} years old", ['Sara', 12]); >>> Hello, my name is Sara, I’m 12 years old // Decimals and integers echo __('You have traveled {0,number,decimal} kilometers in {1,number,integer} weeks', [5423.344, 5.1]); >>> You have traveled 5,423.34 kilometers in 5 weeks Messages
  • 11. echo __('{0,plural, =0{No records found} =1{Found 1 record} other{Found # records}}', [1]); >>> Found 1 record // Simpler message ids. echo __('records.found', [1]); >>> Found 1 record Plurals
  • 12. msgid "One file removed" msgid_plural "{0} files removed" msgstr[0] "jednom datotekom je uklonjen" msgstr[1] "{0} datoteke uklonjenih" msgstr[2] "{0} slika uklonjenih" Catalog Files
  • 13. use CakeI18nTime; use CakeI18nNumber; $date = new Time('2015-04-05 23:00:00'); echo $date; >>> 05/04/2015 23:00 echo Number::format(524.23); >>> 524.23 Numbers & Dates
  • 14. Locale::setDefault(‘fr-FR’); $date = new Time('2015-04-05 23:00:00'); echo $date; >>> 5 avril 2015 23:00:00 UTC echo Number::format(524.23); >>> 524,23 Numbers & Dates
  • 15. Use Alone Use the i18n libs anywhere with composer.
  • 17. Router::scope(‘/u‘, function ($routes) { $routes->connect(‘/name/:username’, [‘controller’ => ‘Users’, ’action’ => ‘show’]); }); // Use namespace prefixed controllers. Router::prefix(‘admin’, function ($routes) { $routes->connect(‘/articles/:action’, [‘controller’ => ‘Articles’]); }); Routing Scopes
  • 18. // Classic array format. echo $this->Url->build([ ‘controller’ => ‘Users’, ‘action’ => ‘show’, ‘username’ => ‘thewoz’ ]); >>> /u/name/thewoz echo $this->Url->build([ ‘prefix’ => ‘Admin’, ‘controller’ => ‘Articles’, ‘action’ => ‘index’ ]); >>> /admin/articles/index Reverse Routing
  • 19. Router::scope(‘/u‘, function ($routes) { // Explicit name $routes->connect(‘/friends’, [‘controller’ => ‘Friends’], [‘_name’ => ‘u:friends’]); }); echo $this->Url->build([‘_name’ => ‘u:friends’]); >>> /u/friends Named Routes
  • 20. Router::scope('/', function ($routes) { $routes->extensions(['json']); $routes->resources('Articles'); }); >>> /articles and /articles/:id are now connected. // Generate nested resources Router::scope('/', function ($routes) { $routes->extensions([‘json’]); $routes->resources('Articles', function ($routes) { $routes->resources('Comments'); }); }); >>> /articles/:article_id/comments is now connected. Resource Routing
  • 23. Immutable Mutator methods make new collections.
  • 24. $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); // Create a new collection containing elements // with a value greater than one. $big = $collection->filter(function ($value, $key, $iterator) { return $value > 1; }); // Search data in memory. match() makes a new iterator $collection = new Collection($comments); $commentsFromMark = $collection->match(['user.name' => 'Mark']); Improved Arrays
  • 25. $people = new Collection($peopleData); // Find all the non-blondes $notBlond = $people->reject(function ($p) { return $p->hair_colour === ‘blond’; }); // Get all the people named jose $joses = $notBlond->filter(function ($p) { return strtolower($p->first_name) === ‘jose’; }); // Count by their hair colour $counts = $joses->countBy(function ($p) { return $p->hair_colour; }); Pipeline Example
  • 26. class JoseFinder { public function __invoke($person) { return strtolower($person->first_name) === ‘jose’; } } $joses = $people->filter(new JoseFinder()); $notBlond = $people->reject(new NotBlondFilter()); Pipeline ++
  • 27. Use Alone Collections can be used in any project.
  • 28. ORM
  • 29. It is not 2005 anymore
  • 31. // Get a table gateway/mapper. $connection = ConnectionManager::get(‘default’); $articles = new ArticlesTable([‘connection’ => $connection]); // Basic query building $query = $articles->find() ->where([‘Articles.author_id’ => $userid]) ->order([‘Articles.created’ => ‘DESC’]); // Find some published, promoted articles $query = $articles->find(‘promoted’) ->find(‘published’); Finding Records
  • 32. // Find articles and eager load relations (1 query) $query = $articles->find() ->contain([‘Authors’, ‘Categories’]); // Load deeply nested relations (2 queries) $query = $articles->find() ->contain([‘Authors.RecentActivities’]); Eager Loading
  • 33. // Find all the articles tagged with ‘Cat’ $query = $articles->find()->matching(‘Tags’, function ($q) { return $q->where([‘Tags.name’ => ‘Cat’]); }); // Find all the articles without the tag ‘Cat’ $query = $articles->find()->notMatching(‘Tags’, function ($q) { return $q->where([‘Tags.name’ => ‘Cat’]); }); Matching
  • 34. // Do extraction and transformations $result = $articles->find() ->all() ->extract(‘title’) ->map(function ($item) { return strtoupper($item); }); // Extract and reduce $query = $articles->find()->contain([‘Tags’]); $uniqueTags = $articles->all() ->extract(‘tags.{*}.name’) ->reduce(function ($out, $tag) { if (!in_array($tag, $out) { $out[] = $tag; } return $out; }, []); Collections+
  • 35. Entities Just vanilla PHP objects for the most part.
  • 36. namespace AppModelEntity; use CakeORMEntity; class Article extends Entity { protected $_accessible = [‘title’, ‘body’, ‘author_id’]; } Article Entity
  • 37. namespace AppModelEntity; use CakeORMEntity; class User extends Entity { protected function _getFullName() { return $this->_properties['first_name'] . ' ' . $this->_properties['last_name']; } } echo $user->full_name; Virtual Fields
  • 38. Inspired By SQLAlchemy The best ORM I’ve ever used.
  • 39. No Proxies, No Annotations, No Identity Map, No Runtime Reflection
  • 41. Use alone Use the ORM anywhere with composer.
  • 43. What’s Next • New DateTime library, replacing Carbon • Polymorphic Associations • PSR7 Support • Value Objects