Slide 1

Slide 1 text

CakePHP 3.0 The cake isn't a lie and it tastes delicious Justin Yost Web Developer at Loadsys

Slide 2

Slide 2 text

What is CakePHP • MVC Driven OO PHP Framework • Heavily focused on Conventions over Configuration • CakePHP will be 10 years old in May(ish)

Slide 3

Slide 3 text

Goodies in CakePHP • Limited to no configuration needed to get running • Most everything you need is built in • Super easy to rip out anything you dislike and replace with your own (this wasn't always true)

Slide 4

Slide 4 text

Changes in CakePHP 3.0 • Follows PSR-4 and PSR-2 (which means also PSR-1) standards • Composer is the only supported way to install CakePHP • Namespaces • Heavy focus on making the CakePHP Core even more extensible and decoupled • Getting rid of the cruft that has built up over the years

Slide 5

Slide 5 text

Changes in CakePHP 3.0 • Brand new ORM with tons of cool features • Routing improved and made much faster and simpler • HTTP Classes rewritten to focus on modern HTTP world (dealing with PHP Streams, OAuth, etc) • Throwing out the idea that CakePHP does things in it's own weird way for some common problems (Aura.Intl for example)

Slide 6

Slide 6 text

How do I use CakePHP 3.0? • Current release is the 1st RC (released Jan. 2, 2015) composer create-project --prefer-dist -s dev cakephp/app [app_name]

Slide 7

Slide 7 text

CakePHP - Bake • Bake is CakePHP's way of generating the basic Model, View, Controller layer given a database schema • So I've loaded a database schema in here already for a simple bookmark system, that is provided from CakePHP's documemation bin/cake bake all users bin/cake bake all bookmarks bin/cake bake all tags

Slide 8

Slide 8 text

So what do we have? • http://vagrant.dev:8080/

Slide 9

Slide 9 text

Password Hashing • src/Model/Entity/User.php

Slide 10

Slide 10 text

Find Bookmarks matching a tag • config/routes.php • src/Controller/BookmarksController.php • src/Model/Table/BookmarksTable.php • src/Template/Bookmarks/tags.ctp

Slide 11

Slide 11 text

Let's talk about the new ORM • There are now two primary Objects in the ORM: • Tables: "These objects provide access to collections of data. They allow you to save new records, modify/delete existing ones, define relations, and perform bulk operations." • Entities: "Entities represent individual records and allow you to define row/record level behavior & functionality."

Slide 12

Slide 12 text

Bad things Pre 3.0 • Results were arrays not objects • Couldn't stack model/database calls • No query object (sub-queries/unions were hard in Cake's ORM) • No attaching a method to happen on adding/editing/ returning a field in a database, only attaching at the overall Model level • Other issues

Slide 13

Slide 13 text

So what's cool about the new version? • Make everything return query objects and stack at will

Slide 14

Slide 14 text

Example: • src/Controller/BookmarksController.php

Slide 15

Slide 15 text

So you can stack something like? Students are allowed to retake their lowest quiz grade within the last 14 days iff it is above a 50% $this->Grades->find('students')->find('quiz')->find('date_range')->find('lowest')->find('above50')

Slide 16

Slide 16 text

That's the biggest change in Cake 3.0 • Everything else is secondary to the ORM if you have used Cake before hand

Slide 17

Slide 17 text

Personal history with CakePHP • I learned it back in the 1.2 era (2008-ish) and haven't really left it since then • Cake 2.x era has been great for the CakePHP community • Cake 2.x has rarely felt like I was missing something or the framework was preventing me from doing something • Cake 3.x gets rid of pretty much every negative association you could have had with CakePHP from the past and gives you a whole new underlying core without a hard transition

Slide 18

Slide 18 text

Questions? Justin Yost Developer at Loadsys https://www.yostivanich.com/ twitter.com/jtyost2 github.com/jtyost2/LasVegas-CakePHP3-Intro