CakePHP
Build fast, grow solid.
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.
•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
What is 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
What is CakePHP?
The 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
CakeFest
CakeFest
Learn new skills
Meet awesome people
Eat cake
CakeSwag
swag.cakephp.org
Get unique T-Shirts, ElePHPants
and mugs
The core team
What’s new in 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 7)
•Middleware oriented stack
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)
Database migrations (Thanks to Phinx)
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
cakephp/authentication
cakephp/phinx
cakephp/i18n
PSR-7 support
•3.4 is fully PSR-7 compatible
•Uses a middleware stack
•Both request and response objects are immutable
•A large collection of middleware already included, and most other
middleware is supported
The future
The future*
•3.5 – Middle 2017
•Routable Middleware
•Migrating certain bits of functionality into middleware
•3.6 – End 2017
•Route builder DSL
•Replace Shell with a Command builder
•Hard deprecate the soft deprecated functionality
•4.0 – Early 2018
•Clean-up by removing all deprecated functionality

https://github.com/cakephp/cakephp/wiki

https://bakery.cakephp.org/2017/06/23/upcoming-cakephp-roadmap.html
* Subject to change depending on community feedback
The future*
•2.x long term support?
•Bug fixes for 12 months
•Security fixes for 18 months
•3.x long term support?
•Bug fixes for 18 months
•Security fixes for 36 months
* Subject to change depending on community feedback
Let’s get baking
Installing 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!
•Download Oven from https://github.com/cakedc/oven
•Put the oven.php file on your server
•Open the script in your browser (etc. http://localhost/oven.php)
Now even, easier than baking a cake with
•A web-based CakePHP plugin installer
•Helps you discover new CakePHP plugins
•Includes “Kitchen” which is a web-frontend for the Cake Bake tool (More on that later)
•Install with composer, or with Oven
•Access via http://localhost/mixer
Introducing
Create a database
•Schema from https://book.cakephp.org/3.0/en/tutorials-and-examples/cms/
database.html
Skip the hard work
$ bin/cake bake all users
$ bin/cake bake all articles
$ bin/cake bake all tags
$ bin/cake bake all --everything
Less typey-typey, more clicky-clicky
What? A working application!
Fixing broken stuff
•Interactive stack trace
•Method argument inspection
•Possible solution hints
•Inspired by Whoops!
DebugKit
•CakePHP 3 comes with a debug
toolbar pre-installed
•Facilitates in-depth application
inspection
•Continuously being improved
Putting the rapid into RAD
•How do we prevent repetitive controller code?
•How do we have both a web and REST interface?
•How about a JSON API spec compatible 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 OR use Mixer
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');

}
Creating a REST API
$ curl –X GET localhost:8765/articles -H ‘Accept: application/json’
{
"success": true,
"data": [
{
"id": 1,
"user_id": 1,
"title": "First Post",
"slug": "first-post",
"body": "This is the first post.",
"published": true,
"created": "2017-07-03T17:23:06+00:00",
"modified": "2017-07-03T17:23:06+00:00"
}
],
"pagination": {
"page_count": 1,
"current_page": 1,
"has_next_page": false,
"has_prev_page": false,
"count": 1,
"limit": null
}
}
But, I want JSON API
•Converts all actions into a web service capable of responding in spec complaint JSON API
•Takes care of all error handling and validation errors as per the JSON API spec
•Works with the standard JSON API too
public function initialize()

{

...

$this->loadComponent('RequestHandler');



$this->Crud->addListener(‘CrudJsonApi.JsonApi');

}
$ composer require friendsofcake/crud-json-api OR use Mixer
JSON API
$ curl –X GET ‘localhost:8765/articles?include=users’ -H ‘Accept: application/vnd.api+json’
{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
"title": "First Post",
"slug": "first-post",
"body": "This is the first post.",
"published": true,
"created": "2017-07-03T17:25:23+00:00",
"modified": "2017-07-03T17:25:23+00:00"
},
"relationships": {
"user": {
"data": {
"type": "users",
"id": "1"
},
"links": {
"self": "/users/view/1"
}
}
},
"links": {
"self": "/articles/view/1"
}
}
],
"included": [
{
"type": "users",
"id": "1",
"attributes": {
"email": "cakephp@example.com",
"created": "2017-07-03T17:25:23+00:00",
"modified": "2017-07-03T17:25:23+00:00"
},
"links": {
"self": "/users/view/1"
}
}
]
}
Why write HTML?
•Generate always-up-to-date admin interfaces
•Delete all your template files
public function initialize()

{

...

$this->loadComponent('RequestHandler');



$this->Crud->addListener(‘CrudView.View’);

}
public function beforeRender()

{ 

$this->viewBuilder()->className(‘CrudViewViewCrudView’);

}
$ composer require friendsofcake/crud-view OR use Mixer (Also install friendsofcake/bootstrap-ui)
Other awesome plugins
•TinyAuth – Light weight role based authentication
•Friends of Cake Search – Simple interface for creating paginate-able filters
•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
and via Mixer
Also keep an eye on the @cakephp twitter feed for weekly featured plugins!
Walther Lalk
CakePHP core team member
Croogo core team member
Software Developer at
Troop Scouter at 9th Pretoria (Irene) Air Scouts
Husband
github.com/dakota
@dakotairene
waltherlalk.com
Thank you
github.com/dakota
@dakotairene
waltherlalk.com
Don’t forget to buy Swag!
swag.cakephp.org

Intro to CakePHP

  • 1.
  • 2.
  • 3.
    What is CakePHP? CakePHP isa 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.
  • 4.
    •One of theoriginal 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 What is CakePHP?
  • 5.
    •Active and friendlycommunity •A core team of highly motivated and experienced developers •Long support life cycles for major releases •Backwards compatibility between minor releases What is CakePHP?
  • 6.
    The 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
  • 7.
  • 8.
    CakeFest Learn new skills Meetawesome people Eat cake
  • 9.
  • 10.
  • 11.
    What’s new inCakePHP 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 7) •Middleware oriented stack
  • 12.
    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) Database migrations (Thanks to Phinx)
  • 13.
    Standalone packages •You canuse 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 cakephp/authentication cakephp/phinx cakephp/i18n
  • 14.
    PSR-7 support •3.4 isfully PSR-7 compatible •Uses a middleware stack •Both request and response objects are immutable •A large collection of middleware already included, and most other middleware is supported
  • 15.
  • 16.
    The future* •3.5 –Middle 2017 •Routable Middleware •Migrating certain bits of functionality into middleware •3.6 – End 2017 •Route builder DSL •Replace Shell with a Command builder •Hard deprecate the soft deprecated functionality •4.0 – Early 2018 •Clean-up by removing all deprecated functionality
 https://github.com/cakephp/cakephp/wiki
 https://bakery.cakephp.org/2017/06/23/upcoming-cakephp-roadmap.html * Subject to change depending on community feedback
  • 17.
    The future* •2.x longterm support? •Bug fixes for 12 months •Security fixes for 18 months •3.x long term support? •Bug fixes for 18 months •Security fixes for 36 months * Subject to change depending on community feedback
  • 18.
  • 19.
    Installing CakePHP Full virtualenvironment available https:// github.com/FriendsOfCake/vagrant-chef $ composer create-project cakephp/app $ cd app && bin/cake server Easier than baking a cake!
  • 20.
    •Download Oven fromhttps://github.com/cakedc/oven •Put the oven.php file on your server •Open the script in your browser (etc. http://localhost/oven.php) Now even, easier than baking a cake with
  • 24.
    •A web-based CakePHPplugin installer •Helps you discover new CakePHP plugins •Includes “Kitchen” which is a web-frontend for the Cake Bake tool (More on that later) •Install with composer, or with Oven •Access via http://localhost/mixer Introducing
  • 27.
    Create a database •Schemafrom https://book.cakephp.org/3.0/en/tutorials-and-examples/cms/ database.html
  • 28.
    Skip the hardwork $ bin/cake bake all users $ bin/cake bake all articles $ bin/cake bake all tags $ bin/cake bake all --everything
  • 29.
  • 30.
    What? A workingapplication!
  • 31.
    Fixing broken stuff •Interactivestack trace •Method argument inspection •Possible solution hints •Inspired by Whoops!
  • 32.
    DebugKit •CakePHP 3 comeswith a debug toolbar pre-installed •Facilitates in-depth application inspection •Continuously being improved
  • 33.
    Putting the rapidinto RAD •How do we prevent repetitive controller code? •How do we have both a web and REST interface? •How about a JSON API spec compatible 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
  • 34.
    Installing CRUD •Remove allcode 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 OR use Mixer
  • 35.
    Creating a RESTAPI •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');
 }
  • 36.
    Creating a RESTAPI $ curl –X GET localhost:8765/articles -H ‘Accept: application/json’ { "success": true, "data": [ { "id": 1, "user_id": 1, "title": "First Post", "slug": "first-post", "body": "This is the first post.", "published": true, "created": "2017-07-03T17:23:06+00:00", "modified": "2017-07-03T17:23:06+00:00" } ], "pagination": { "page_count": 1, "current_page": 1, "has_next_page": false, "has_prev_page": false, "count": 1, "limit": null } }
  • 37.
    But, I wantJSON API •Converts all actions into a web service capable of responding in spec complaint JSON API •Takes care of all error handling and validation errors as per the JSON API spec •Works with the standard JSON API too public function initialize()
 {
 ...
 $this->loadComponent('RequestHandler');
 
 $this->Crud->addListener(‘CrudJsonApi.JsonApi');
 } $ composer require friendsofcake/crud-json-api OR use Mixer
  • 38.
    JSON API $ curl–X GET ‘localhost:8765/articles?include=users’ -H ‘Accept: application/vnd.api+json’ { "data": [ { "type": "articles", "id": "1", "attributes": { "title": "First Post", "slug": "first-post", "body": "This is the first post.", "published": true, "created": "2017-07-03T17:25:23+00:00", "modified": "2017-07-03T17:25:23+00:00" }, "relationships": { "user": { "data": { "type": "users", "id": "1" }, "links": { "self": "/users/view/1" } } }, "links": { "self": "/articles/view/1" }
  • 39.
    } ], "included": [ { "type": "users", "id":"1", "attributes": { "email": "cakephp@example.com", "created": "2017-07-03T17:25:23+00:00", "modified": "2017-07-03T17:25:23+00:00" }, "links": { "self": "/users/view/1" } } ] }
  • 40.
    Why write HTML? •Generatealways-up-to-date admin interfaces •Delete all your template files public function initialize()
 {
 ...
 $this->loadComponent('RequestHandler');
 
 $this->Crud->addListener(‘CrudView.View’);
 } public function beforeRender()
 { 
 $this->viewBuilder()->className(‘CrudViewViewCrudView’);
 } $ composer require friendsofcake/crud-view OR use Mixer (Also install friendsofcake/bootstrap-ui)
  • 42.
    Other awesome plugins •TinyAuth– Light weight role based authentication •Friends of Cake Search – Simple interface for creating paginate-able filters •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 and via Mixer Also keep an eye on the @cakephp twitter feed for weekly featured plugins!
  • 43.
    Walther Lalk CakePHP coreteam member Croogo core team member Software Developer at Troop Scouter at 9th Pretoria (Irene) Air Scouts Husband github.com/dakota @dakotairene waltherlalk.com
  • 44.
  • 45.
    Don’t forget tobuy Swag! swag.cakephp.org