Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CakePHP 3 Intro

Justin Yost
February 04, 2015

CakePHP 3 Intro

Introduction to CakePHP 3.0, given to the Las Vegas PHP Meetup.

Justin Yost

February 04, 2015
Tweet

More Decks by Justin Yost

Other Decks in Programming

Transcript

  1. CakePHP 3.0 The cake isn't a lie and it tastes

    delicious Justin Yost Web Developer at Loadsys
  2. What is CakePHP • MVC Driven OO PHP Framework •

    Heavily focused on Conventions over Configuration • CakePHP will be 10 years old in May(ish)
  3. 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)
  4. 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
  5. 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)
  6. 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]
  7. 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
  8. Find Bookmarks matching a tag • config/routes.php • src/Controller/BookmarksController.php •

    src/Model/Table/BookmarksTable.php • src/Template/Bookmarks/tags.ctp
  9. 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."
  10. 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
  11. So what's cool about the new version? • Make everything

    return query objects and stack at will
  12. 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')
  13. That's the biggest change in Cake 3.0 • Everything else

    is secondary to the ORM if you have used Cake before hand
  14. 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