SlideShare a Scribd company logo
1 of 44
Download to read offline
CakePHP
Build fast, grow solid.
Walther Lalk
CakePHP core team member
Croogo core team member
Lead Software Developer at
Troop Scouter at 9th Pretoria (Irene) Air Scouts
Husband github.com/dakota
@dakotairene
waltherlalk.com
What is CakePHP?
What is CakePHP?
CakePHP is a modern, free, open-source, rapid development framework
for PHP. It's a foundational structure for programmers to create web
applications. Our primary goal is to enable you to work in a structured
and rapid manner–without loss of flexibility. CakePHP takes the
monotony out of web development.
CakePHP?
•One of the original PHP frameworks, dating from late 2004
•An opinionated MVC framework
•Convention over configuration
•Encourages DRY coding principles
•Aims to solve 80% of the problem, and then stay out of your way
CakePHP?
•Active and friendly community
•A core team of highly motivated and experienced developers
•Long support life cycles for major releases
•Backwards compatibility between minor releases
A short history lesson
CakePHP
project started

Early 2005
1.0 released

May 2006
2.0 released

October 2011
3.0 released
March 2015
A new brand for a new era
•PHP world has matured greatly since CakePHP 1.0 and 2.0
•An updated, modern re-imagining of CakePHP was needed with greater
interoperability with the rest of the PHP eco-system
•PHP-FIG (CakePHP was a founding member)
•Composer
•Components
•CakePHP 3.0 was released at CakeFest 2015
•A new, modern brand was announced at CakeFest 2016
CakeFest
•Annual CakePHP conference
•Soon to be twice annually
•2 days of workshops (With a
beginner and advanced track)
•2 days of talks from industry
experts and local developers
CakePHP Community
•Active, supportive and helpful community
•CakePHP Forum – discourse.cakephp.org
•Slack and IRC – cakesf.herokuapp.com
•Stackoverflow
•Large eco-system of plugins and packages
•Regular live training sessions – training.cakephp.org
•An awesome full-time community manager – community@cakephp.org
•@cakephp
CakePHP 3
•A new ORM that is powerful, flexible and lightweight
•Simple Form generator
•Internationalization out the box (And it makes sense)
•Standards complaint (PSR-2, 3, 4 and soon 7)
•Middleware oriented stack
Standalone packages
•You can use bits of CakePHP without using CakePHP
•Separate components that can be used in any PHP project
cakephp/cache

cakephp/event

cakephp/validation

cakephp/orm

cakephp/collection
Collections
use CakeCollectionCollection;



$items = [

['id' => 1, 'name' => 'foo', 'parent' => 'a'],

['id' => 2, 'name' => 'bar', 'parent' => 'b'],

['id' => 3, 'name' => 'baz', 'parent' => 'a'],

];



$combined = (new Collection($items))->combine('id', 'name', 'parent');



// Result will look like this when converted to array

[

'a' => [1 => 'foo', 3 => 'baz'],

'b' => [2 => 'bar']

];
Collections
<?php
$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);
$new = $collection->map(function ($value, $key) {
return $value * 2;
});
// $result contains ['a' => 2, 'b' => 4, 'c' => 6];
$result = $new->toArray();
Powerful ORM and query builder
Looks and feels like SQL (Mostly)
$query->select(['name', 'email'])->where(['status IN' => ['active', 'pending']])->orderDesc('created');
$premium = $users->find('active')->find('premium'));

$subscribers = $users->find('active')->find('subscribedToNewsletter');
$query = $users->find()->select(['id'])->where(['is_active' => true]);

$anotherQuery->innerJoin(['stuff' => $query]);

$anotherQuery->where(['id IN' => $query]);
$recipients = $premium->append($subscribers)->extract('email');
Queries can be composed
Everything can be an expression
Queries are collections
Filtering by associations
// UsersTable

public function findWithArticlesNewerThanUser(Query $query, $options)

{

$userDate = $this->find()

->select(['created'])

->where(['id' => $options['userId']]);



return $query

->matching('Articles', function ($q) use ($userDate) {

return $q->where(['created >=' => $userDate]); 

});

}
Post-processing
public function findInContinentGroups(Query $query)

{

$query->formatResults(function ($results) {

return $results->groupBy('continent');

});



return $query;

}
"Africa": [

{

"name": "Angola"

},

{

"name": "Burundi"

},

{

"name": "Benin"

},

{

"name": "Burkina Faso"

},

],

"America": [...
Map-reduce
$mapper = function ($article, $key, $mapReduce) {

if (stripos('cakephp', $article['body']) === false) {

return;

}



$words = array_map('strtolower', explode(' ', $article['body']));

foreach ($words as $word) {

$mapReduce->emitIntermediate($article['id'], $word);

}

};



$reducer = function ($occurrences, $word, $mapReduce) {

$mapReduce->emit(count($occurrences), $word);

}



$articlesByStatus = $articles->find()->mapReduce($mapper, $reducer);
Map-reduce
// Result

[

'cakephp' => 100,

'awesome' => 39,

'impressive' => 57,

'outstanding' => 10,

'mind-blowing' => 83

]
PSR-7 support
•3.3 introduced a PSR-7 compatible middleware stack
•Both request and response objects are immutable
•Application level request/response objects are not PSR-7 (Yet!)
Middleware
CORS
Exceptions
Assets
Routes
App
Middleware
CORS
Exceptions
Assets
Routes
App
Request
Response
Middleware
CORS
Exceptions
Assets
Routes
AppRequest
Response
Rules to follow
•Must accept a Request, Response and ‘next’
•Must return a Response or call ‘next’
Doesn’t have to be limited to the CakePHP eco-system

For example, https://github.com/oscarotero/psr7-middlewares has a collection of
generic middleware classes.
Middleware setup
$middleware = new CakeHttpMiddlewareQueue();



$middleware

// Catch any exceptions in the lower layers,

// and make an error page/response

->add(new ErrorHandlerMiddleware())



// Handle plugin/theme assets like CakePHP normally does.

->add(new AssetMiddleware())



// Apply routing

->add(new RoutingMiddleware());



// Apply CORS as the first middleware

$middleware->prepend(new CorsMiddleware());
Middleware setup
// Oh wow, closures

$ohWow = function ($req, $res, $next) {

$res = $res->withHeader('X-WOW', 'Oh wow!');



return $next($req, $res);

};


// Add to the middleware stack

$middleware->add($ohWow);
Middleware setup
class OhWowMiddleware

{

public function __invoke($req, $res, $next)

{

$res = $res->withHeader('X-WOW', 'Oh wow!');



return $next($req, $res);

}

}



// Add to the middleware stack

$middleware->add(new OhWowMiddleware());
Easy, one-liner pagination (Even for complex queries)
Automatic association saving
Flexible association strategies
Result streaming
Query caching
Finder callbacks
Composite key support (Including foreign keys)
Tree structures
CSRF protection
Form tampering protection
Mailer classes
Authentication
Code generation
Advanced date and time support (Thanks to the Chronos library)
The future
The future*
•3.4 – Early 2017
•PSR-7 request objects
•Conditional Middleware’s (aka Pipelines)
•3.5 – Probably middle 2017
•PSR-7 response objects
•Migrating certain bits of functionality into middleware
•3.6 – Probably end 2017
•Hard deprecate the soft deprecated functionality
•4.0 – Maybe early 2018
•Clean-up by removing all deprecated functionality
https://github.com/cakephp/cakephp/wiki
* Subject to change depending on community feedback
Let’s get baking
Install CakePHP
Full virtual environment available https://
github.com/FriendsOfCake/vagrant-chef
$ composer create-project cakephp/app
$ cd app && bin/cake server
Easier than baking a cake!
Initial database migration
$ bin/cake migrations create Initial
$ bin/cake migrations migrate
Create an empty migration file
$ bin/cake bake migration_snapshot Initial
Create a migration based on an existing database
$ bin/cake bake migration CreateBookmarks user_id:integer title:string[50]
description:text url:text created modified
Build a migration in the console
Run migrations
Initial database migration
$this->table('bookmarks')

->addColumn('user_id', 'integer')

->addColumn('title', 'string', ['limit' => 50])

->addColumn('description', 'text')

->addColumn('url', 'text')

->addColumn('created', 'datetime')

->addColumn('modified', 'datetime')

->create();



$this->table('bookmarks_tags', ['id' => false, 'primary_key' =>
['bookmark_id', 'tag_id']])

->addColumn('bookmark_id', 'integer')
…
Skipping the hard work
$ bin/cake bake all users
$ bin/cake bake all bookmarks
$ bin/cake bake all tags
$ bin/cake bake all --everything
Fixing broken stuff
•Interactive stack trace
•Method argument inspection
•Possible solution hints
DebugKit
•CakePHP 3 comes with a debug
toolbar pre-installed
•Facilitates in-depth application
inspection
Putting the rapid into RAD
•How do we prevent repetitive controller code?
•How do we have both a web and REST interface?
•How do we do this without creating messy spaghetti code?
The CRUD plugin
•Dynamic, event-driven and production ready scaffolding
•Automatic REST API generation
•Single responsibility action classes
Installing CRUD
•Remove all code from your controllers
•Go on holiday, your work is done
class AppController extends Controller

{

use CrudControllerControllerTrait;



public function initialize()

{

$this->loadComponent('Crud.Crud', [

'actions' => [

'Crud.Index',

'Crud.Add',

'Crud.Edit',

'Crud.View',

'Crud.Delete'

]

]);

}

}
$ composer require friendsofcake/crud
Creating a REST API
•Converts all actions into a web service capable of responding in JSON or XML
•Takes care of all error handling and validation errors
•Automatically adds a “layout” to your responses
// config/routes.php

$routes->extensions(['json', 'xml']);
public function initialize()

{

...

$this->loadComponent('RequestHandler');



$this->Crud->addListener('Crud.Api');

$this->Crud->addListener('Crud.ApiPagination');

$this->Crud->addListener('Crud.ApiQueryLog');

}
$ curl –X GET localhost:8765/tags.json
Extending Crud with events
Limiting records by user
Remembering the bookmark creator
$this->Crud->on('beforePaginate', function (CakeEventEvent $event) {

$event->subject()->query->where(['Bookmarks.user_id' => $this->Auth->user('id')]);

});
$this->Crud->on('beforeSave', function (CakeEventEvent $event) {

$event->subject()->entity->user_id = $this->Auth->user('id');

});
Other awesome plugins
•TinyAuth – Light weight role based authentication
•Friends of Cake Search – Simple interface for creating paginate-able filters
•FractalTransformerView – Use Fractal to render API responses
•TwigView – Use Twig for your templates
•Liquid – Use Liquid for your templates
•CakePDF – Easily create PDF files
•The Queue plugin – Dependency-free worker queues
Many many more available from https://github.com/friendsofcake/awesome-cakephp
Also keep an eye on the @cakephp twitter feed for weekly featured plugins!
Thank You.
github.com/dakota
@dakotairene
waltherlalk.com

More Related Content

What's hot

Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
Web deveopment using React js and Node js with SQL.
Web deveopment using React js and Node js with SQL.Web deveopment using React js and Node js with SQL.
Web deveopment using React js and Node js with SQL.Jayant Surana
 
Laravel Routing and Query Building
Laravel   Routing and Query BuildingLaravel   Routing and Query Building
Laravel Routing and Query BuildingMindfire Solutions
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해beom kyun choi
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIRasan Samarasinghe
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Expressjguerrero999
 
Route 路由控制
Route 路由控制Route 路由控制
Route 路由控制Shengyou Fan
 
Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Securitygeorge.james
 
FHIR Server 安裝與使用
FHIR Server 安裝與使用FHIR Server 安裝與使用
FHIR Server 安裝與使用Lorex L. Yang
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeAbhishek L.R
 
Grails Connecting to MySQL
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQLashishkirpan
 
Django class based views for beginners
Django class based views for beginnersDjango class based views for beginners
Django class based views for beginnersSpin Lai
 
Introduction to web application development
Introduction to web application developmentIntroduction to web application development
Introduction to web application developmentAyyappadhas K B
 

What's hot (20)

Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Web deveopment using React js and Node js with SQL.
Web deveopment using React js and Node js with SQL.Web deveopment using React js and Node js with SQL.
Web deveopment using React js and Node js with SQL.
 
Laravel Routing and Query Building
Laravel   Routing and Query BuildingLaravel   Routing and Query Building
Laravel Routing and Query Building
 
Webcrawler
Webcrawler Webcrawler
Webcrawler
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST API
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Chapter2 j2ee
Chapter2 j2eeChapter2 j2ee
Chapter2 j2ee
 
Route 路由控制
Route 路由控制Route 路由控制
Route 路由控制
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Security
 
FHIR Server 安裝與使用
FHIR Server 安裝與使用FHIR Server 安裝與使用
FHIR Server 安裝與使用
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status Code
 
Grails Connecting to MySQL
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQL
 
Django class based views for beginners
Django class based views for beginnersDjango class based views for beginners
Django class based views for beginners
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Introduction to web application development
Introduction to web application developmentIntroduction to web application development
Introduction to web application development
 

Viewers also liked

Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsPierre MARTIN
 
Consola Cake Php, Uso Y Testing
Consola Cake Php, Uso Y TestingConsola Cake Php, Uso Y Testing
Consola Cake Php, Uso Y Testingdriveros
 
PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3David Yell
 
9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resourcesiScripts
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaionglslarmenta
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHPAndru Weir
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
 

Viewers also liked (10)

Cakephp 3
Cakephp 3 Cakephp 3
Cakephp 3
 
Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP Behaviors
 
Consola Cake Php, Uso Y Testing
Consola Cake Php, Uso Y TestingConsola Cake Php, Uso Y Testing
Consola Cake Php, Uso Y Testing
 
PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3
 
9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources
 
Full-Stack CakePHP Deployment
Full-Stack CakePHP DeploymentFull-Stack CakePHP Deployment
Full-Stack CakePHP Deployment
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHP
 
Cakephp
CakephpCakephp
Cakephp
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 

Similar to CakePHP

Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3kidtangerine
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment Evaldo Felipe
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Adam Tomat
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Modernizing Legacy Applications in PHP, por Paul Jones
Modernizing Legacy Applications in PHP, por Paul JonesModernizing Legacy Applications in PHP, por Paul Jones
Modernizing Legacy Applications in PHP, por Paul JonesiMasters
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to LaravelJason McCreary
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 

Similar to CakePHP (20)

Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Modernizing Legacy Applications in PHP, por Paul Jones
Modernizing Legacy Applications in PHP, por Paul JonesModernizing Legacy Applications in PHP, por Paul Jones
Modernizing Legacy Applications in PHP, por Paul Jones
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 
Modern php
Modern phpModern php
Modern php
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

CakePHP

  • 2. Walther Lalk CakePHP core team member Croogo core team member Lead Software Developer at Troop Scouter at 9th Pretoria (Irene) Air Scouts Husband github.com/dakota @dakotairene waltherlalk.com
  • 4. What is CakePHP? CakePHP is a modern, free, open-source, rapid development framework for PHP. It's a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility. CakePHP takes the monotony out of web development.
  • 5. CakePHP? •One of the original PHP frameworks, dating from late 2004 •An opinionated MVC framework •Convention over configuration •Encourages DRY coding principles •Aims to solve 80% of the problem, and then stay out of your way
  • 6. CakePHP? •Active and friendly community •A core team of highly motivated and experienced developers •Long support life cycles for major releases •Backwards compatibility between minor releases
  • 7. A short history lesson CakePHP project started
 Early 2005 1.0 released
 May 2006 2.0 released
 October 2011 3.0 released March 2015
  • 8. A new brand for a new era •PHP world has matured greatly since CakePHP 1.0 and 2.0 •An updated, modern re-imagining of CakePHP was needed with greater interoperability with the rest of the PHP eco-system •PHP-FIG (CakePHP was a founding member) •Composer •Components •CakePHP 3.0 was released at CakeFest 2015 •A new, modern brand was announced at CakeFest 2016
  • 9.
  • 10. CakeFest •Annual CakePHP conference •Soon to be twice annually •2 days of workshops (With a beginner and advanced track) •2 days of talks from industry experts and local developers
  • 11. CakePHP Community •Active, supportive and helpful community •CakePHP Forum – discourse.cakephp.org •Slack and IRC – cakesf.herokuapp.com •Stackoverflow •Large eco-system of plugins and packages •Regular live training sessions – training.cakephp.org •An awesome full-time community manager – community@cakephp.org •@cakephp
  • 12. CakePHP 3 •A new ORM that is powerful, flexible and lightweight •Simple Form generator •Internationalization out the box (And it makes sense) •Standards complaint (PSR-2, 3, 4 and soon 7) •Middleware oriented stack
  • 13. Standalone packages •You can use bits of CakePHP without using CakePHP •Separate components that can be used in any PHP project cakephp/cache
 cakephp/event
 cakephp/validation
 cakephp/orm
 cakephp/collection
  • 14. Collections use CakeCollectionCollection;
 
 $items = [
 ['id' => 1, 'name' => 'foo', 'parent' => 'a'],
 ['id' => 2, 'name' => 'bar', 'parent' => 'b'],
 ['id' => 3, 'name' => 'baz', 'parent' => 'a'],
 ];
 
 $combined = (new Collection($items))->combine('id', 'name', 'parent');
 
 // Result will look like this when converted to array
 [
 'a' => [1 => 'foo', 3 => 'baz'],
 'b' => [2 => 'bar']
 ];
  • 15. Collections <?php $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $new = $collection->map(function ($value, $key) { return $value * 2; }); // $result contains ['a' => 2, 'b' => 4, 'c' => 6]; $result = $new->toArray();
  • 16. Powerful ORM and query builder Looks and feels like SQL (Mostly) $query->select(['name', 'email'])->where(['status IN' => ['active', 'pending']])->orderDesc('created'); $premium = $users->find('active')->find('premium'));
 $subscribers = $users->find('active')->find('subscribedToNewsletter'); $query = $users->find()->select(['id'])->where(['is_active' => true]);
 $anotherQuery->innerJoin(['stuff' => $query]);
 $anotherQuery->where(['id IN' => $query]); $recipients = $premium->append($subscribers)->extract('email'); Queries can be composed Everything can be an expression Queries are collections
  • 17. Filtering by associations // UsersTable
 public function findWithArticlesNewerThanUser(Query $query, $options)
 {
 $userDate = $this->find()
 ->select(['created'])
 ->where(['id' => $options['userId']]);
 
 return $query
 ->matching('Articles', function ($q) use ($userDate) {
 return $q->where(['created >=' => $userDate]); 
 });
 }
  • 18. Post-processing public function findInContinentGroups(Query $query)
 {
 $query->formatResults(function ($results) {
 return $results->groupBy('continent');
 });
 
 return $query;
 } "Africa": [
 {
 "name": "Angola"
 },
 {
 "name": "Burundi"
 },
 {
 "name": "Benin"
 },
 {
 "name": "Burkina Faso"
 },
 ],
 "America": [...
  • 19. Map-reduce $mapper = function ($article, $key, $mapReduce) {
 if (stripos('cakephp', $article['body']) === false) {
 return;
 }
 
 $words = array_map('strtolower', explode(' ', $article['body']));
 foreach ($words as $word) {
 $mapReduce->emitIntermediate($article['id'], $word);
 }
 };
 
 $reducer = function ($occurrences, $word, $mapReduce) {
 $mapReduce->emit(count($occurrences), $word);
 }
 
 $articlesByStatus = $articles->find()->mapReduce($mapper, $reducer);
  • 20. Map-reduce // Result
 [
 'cakephp' => 100,
 'awesome' => 39,
 'impressive' => 57,
 'outstanding' => 10,
 'mind-blowing' => 83
 ]
  • 21. PSR-7 support •3.3 introduced a PSR-7 compatible middleware stack •Both request and response objects are immutable •Application level request/response objects are not PSR-7 (Yet!)
  • 25. Rules to follow •Must accept a Request, Response and ‘next’ •Must return a Response or call ‘next’ Doesn’t have to be limited to the CakePHP eco-system
 For example, https://github.com/oscarotero/psr7-middlewares has a collection of generic middleware classes.
  • 26. Middleware setup $middleware = new CakeHttpMiddlewareQueue();
 
 $middleware
 // Catch any exceptions in the lower layers,
 // and make an error page/response
 ->add(new ErrorHandlerMiddleware())
 
 // Handle plugin/theme assets like CakePHP normally does.
 ->add(new AssetMiddleware())
 
 // Apply routing
 ->add(new RoutingMiddleware());
 
 // Apply CORS as the first middleware
 $middleware->prepend(new CorsMiddleware());
  • 27. Middleware setup // Oh wow, closures
 $ohWow = function ($req, $res, $next) {
 $res = $res->withHeader('X-WOW', 'Oh wow!');
 
 return $next($req, $res);
 }; 
 // Add to the middleware stack
 $middleware->add($ohWow);
  • 28. Middleware setup class OhWowMiddleware
 {
 public function __invoke($req, $res, $next)
 {
 $res = $res->withHeader('X-WOW', 'Oh wow!');
 
 return $next($req, $res);
 }
 }
 
 // Add to the middleware stack
 $middleware->add(new OhWowMiddleware());
  • 29. Easy, one-liner pagination (Even for complex queries) Automatic association saving Flexible association strategies Result streaming Query caching Finder callbacks Composite key support (Including foreign keys) Tree structures CSRF protection Form tampering protection Mailer classes Authentication Code generation Advanced date and time support (Thanks to the Chronos library)
  • 31. The future* •3.4 – Early 2017 •PSR-7 request objects •Conditional Middleware’s (aka Pipelines) •3.5 – Probably middle 2017 •PSR-7 response objects •Migrating certain bits of functionality into middleware •3.6 – Probably end 2017 •Hard deprecate the soft deprecated functionality •4.0 – Maybe early 2018 •Clean-up by removing all deprecated functionality https://github.com/cakephp/cakephp/wiki * Subject to change depending on community feedback
  • 33. Install CakePHP Full virtual environment available https:// github.com/FriendsOfCake/vagrant-chef $ composer create-project cakephp/app $ cd app && bin/cake server Easier than baking a cake!
  • 34. Initial database migration $ bin/cake migrations create Initial $ bin/cake migrations migrate Create an empty migration file $ bin/cake bake migration_snapshot Initial Create a migration based on an existing database $ bin/cake bake migration CreateBookmarks user_id:integer title:string[50] description:text url:text created modified Build a migration in the console Run migrations
  • 35. Initial database migration $this->table('bookmarks')
 ->addColumn('user_id', 'integer')
 ->addColumn('title', 'string', ['limit' => 50])
 ->addColumn('description', 'text')
 ->addColumn('url', 'text')
 ->addColumn('created', 'datetime')
 ->addColumn('modified', 'datetime')
 ->create();
 
 $this->table('bookmarks_tags', ['id' => false, 'primary_key' => ['bookmark_id', 'tag_id']])
 ->addColumn('bookmark_id', 'integer') …
  • 36. Skipping the hard work $ bin/cake bake all users $ bin/cake bake all bookmarks $ bin/cake bake all tags $ bin/cake bake all --everything
  • 37. Fixing broken stuff •Interactive stack trace •Method argument inspection •Possible solution hints
  • 38. DebugKit •CakePHP 3 comes with a debug toolbar pre-installed •Facilitates in-depth application inspection
  • 39. Putting the rapid into RAD •How do we prevent repetitive controller code? •How do we have both a web and REST interface? •How do we do this without creating messy spaghetti code? The CRUD plugin •Dynamic, event-driven and production ready scaffolding •Automatic REST API generation •Single responsibility action classes
  • 40. Installing CRUD •Remove all code from your controllers •Go on holiday, your work is done class AppController extends Controller
 {
 use CrudControllerControllerTrait;
 
 public function initialize()
 {
 $this->loadComponent('Crud.Crud', [
 'actions' => [
 'Crud.Index',
 'Crud.Add',
 'Crud.Edit',
 'Crud.View',
 'Crud.Delete'
 ]
 ]);
 }
 } $ composer require friendsofcake/crud
  • 41. Creating a REST API •Converts all actions into a web service capable of responding in JSON or XML •Takes care of all error handling and validation errors •Automatically adds a “layout” to your responses // config/routes.php
 $routes->extensions(['json', 'xml']); public function initialize()
 {
 ...
 $this->loadComponent('RequestHandler');
 
 $this->Crud->addListener('Crud.Api');
 $this->Crud->addListener('Crud.ApiPagination');
 $this->Crud->addListener('Crud.ApiQueryLog');
 } $ curl –X GET localhost:8765/tags.json
  • 42. Extending Crud with events Limiting records by user Remembering the bookmark creator $this->Crud->on('beforePaginate', function (CakeEventEvent $event) {
 $event->subject()->query->where(['Bookmarks.user_id' => $this->Auth->user('id')]);
 }); $this->Crud->on('beforeSave', function (CakeEventEvent $event) {
 $event->subject()->entity->user_id = $this->Auth->user('id');
 });
  • 43. Other awesome plugins •TinyAuth – Light weight role based authentication •Friends of Cake Search – Simple interface for creating paginate-able filters •FractalTransformerView – Use Fractal to render API responses •TwigView – Use Twig for your templates •Liquid – Use Liquid for your templates •CakePDF – Easily create PDF files •The Queue plugin – Dependency-free worker queues Many many more available from https://github.com/friendsofcake/awesome-cakephp Also keep an eye on the @cakephp twitter feed for weekly featured plugins!