SlideShare a Scribd company logo
Ch-ch-anges
 C a k e P H P   2 . 0
CakePHP 2.0
No more PHP4, PHP 5.2.6+

Many re-factored/re-built internal & external
API’s

New features!

Faster!

Updated conventions.
PHP5
Use native features:

  Exceptions.

  Filter ext.

  PDO.

  SPL.

  json_encode()
Conventions
Updated conventions

 ClassName = FileName.php

 View/Helper/HtmlHelper.php =>
 HtmlHelper.

 CamelCased directories.

 Preparing for PHP5.3 and PSR-0
New loader


App::import() - Old and busted.

App::uses() - New hawtness.
Examples
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);




     Classname
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);




     Classname                     Package
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);




     Classname                     Package



      App::uses(‘CakeEmail’, ‘Network/Email’);
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);




     Classname                     Package



      App::uses(‘CakeEmail’, ‘Network/Email’);




      Classname
Examples
App::uses(‘AuthComponent’, ‘Controller/Component’);




     Classname                     Package



      App::uses(‘CakeEmail’, ‘Network/Email’);




      Classname                    Package
Packages

Use App::build() to dene paths where any
package lives.

Sensible defaults come built in.

Undened packages default to checking
app/Lib
paths


Use App::build() to dene paths where
packages can be found.

Can use App::PREPEND and App::APPEND
to control insertion order.
Bad things
 happen
Exceptions

Object::cakeError() is dead.

New Exceptions & Exception handling
replace it.

More extensible and congurable handling.
Example
 1   <?php
 2   // Customize the renderer.
 3   Configure::write('Exception', array(
 4       'handler' => 'ErrorHandler::handleException',
 5       'renderer' => 'MyCustomExceptionRenderer',
 6       'log' => true
 7   ));
 8
 9   // Replace everything.
10   Configure::write('Exception', array(
11       'handler' => function ($e) {
12           echo 'Oh noes';
13       }
14   ));
Built-in exceptions
All previous Object::cakeError() are
exceptions.

Improved testing.

Suite of HTTP exceptions. Great for error
pages.

CakeException for development errors.
Treated as 500 errors in production.
HTTP Exceptions

Most common HTTP exceptions are built in.

The names are what you would expect.

Congured Exception handler will get the
exceptions and render an error page.
HttpExceptions
1 <?php
2 public function view($id = null) {
3     $this->Tag->id = $id;
4     if (!$this->Tag->exists()) {
5         throw new NotFoundException(__('Invalid tag'));
6     }
7     $this->set('tag', $this->Tag->read(null, $id));
8 }
Error Configuration

 Congure used for error/exception settings.

 Sensible defaults.

   Uses Debugger in development

   Logs errors in production.

 You can change out the whole thing.
i18n
i18n


No more true.

Automatic sprintf()
Examples


__(‘Some string’)
Always returns.

__(‘Some %s’, $value);
Does what you want it to.
Unify disparate
     apis
Unify & syngergize

Helper, Components, Behaviors & Tasks.

Similar, but interacting with each was slightly
different.

Collection objects unify all of them.

  HelperCollection, ComponentCollection,
  TaskCollection, BehaviorCollection
Collections

Load objects at runtime.

Unload objects.

Alias objects.

Trigger callbacks.
Loading

$Html = $this->Helpers->load(‘Html’, $settings);


$this->Html works from that point
forward.

The same API exists for components, tasks,
behaviors.
Aliasing

1 <?php
2 public $helpers = array(
3     'Html' => array(
4         'className' => 'MyHtmlHelper'
5     )
6 );
Aliasing

Once an alias is created, that alias is used
everywhere.

With the above controller code, all other
Helpers would use MyHtmlHelper for
$this->Html.
Unload and disable


$this->Components->disable(‘Auth’);

$this->Components->enable(‘Auth’);

$this->Components->unload(‘Auth’);
Callbacks

$this->Helpers->trigger(‘beforeRender’, array
(&$this));

Fires method on all enabled objects.

Implement custom hooks in base classes.
Console
Console
     improvements
Coloured output & output levels.

Less coupled & easier to test.

Better input handling.

Generated help.

XML help. Good for integration with other
tools.
COLORZ

Simple formatting to add styles to output.
$this->out(‘<warning>Uh oh</warning>’);


$this->out(‘<error>Kaboom</error>’);


$this->out(‘<info>Hi</info>’, 1, Shell::VERBOSE);
Input handling

More unix-y input handling.

Long and short options.

Validated options.

Boolean options.

Required arguments.
Generated help

Dening command structure with
ConsoleOptionParser means you get help for
free.

--help and -h supported by all shells.

--help xml generates xml help.
Request &
Response
CakeRequest

Consolidates request interrogation logic.

$this->request everywhere.

Lower memory use by not copying arrays
everywhere.

Backwards compatible read only interface
still around.
CakeResponse

Consolidates response generation.

$this->response everywhere.

Deprecated methods still around.

Controllers can return response objects.
example
1 <?php
2 class PostsController extends AppController {
3     public function simple() {
4         return new CakeResponse(array(
5             'body' => 'Simple response'
6         ));
7     }
8 }
Sessions
Sessions


Sessions were tough in the past.

Custom session handlers weren’t on the same
eld as core ones.
Sessions

Core, App, and Plugin session handlers all
work the same.

CakeSessionInterface interface has to be
implemented.

Same built-in options exist.
Using built-ins
 1   <?php
 2   Configure::write('Session', array(
 3       'defaults' => 'php'
 4   ));
 5   Configure::write('Session', array(
 6       'defaults' => 'database'
 7   ));
 8   Configure::write('Session', array(
 9       'defaults' => 'cache',
10       'handler' => array(
11           'config' => 'session'
12       )
13   ));
Using an app/plugin
  1   <?php
  2   Configure::write('Session', array(
  3       'defaults' => 'database',
  4       'handler' => array(
  5           'engine' => 'Custom'
  6       )
  7   ));
  8   Configure::write('Session', array(
  9       'defaults' => 'php',
 10       'handler' => array(
 11           'engine' => 'Plugin.SessionHandler'
 12       ),
 13       'ini' => array(
 14           'session.cookie_httponly' => true
 15       )
 16   ));
Authorization
AuthComponent

Split into authorization and authentication
adapters.

Easier to modify and extend.

No magic logins.

No magic hashing of passwords.
Built-ins
Authentication     Authorization

  Form.              Controller.

  HTTP Basic.        Actions (Acl)

  HTTP Digest.       CRUD (Acl)

  custom             custom
Logging in
 1 <?php
 2 class UsersController extends AppController {
 3     public function login() {
 4         if ($this->request->is('post')) {
 5             if ($this->Auth->login()) {
 6                 $this->Session->setFlash('Welcome back!');
 7                 $this->redirect($this->Auth->redirect());
 8             } else {
 9                 $this->Session->setFlash('Login credentials were invalid.');
10             }
11         }
12     }
13 }
Auth Configuration


Way less, because there is less magic.

Easier for beginners to grok.

Easier for veterans to customize.
Email
Email

Decomposed into several classes.

Email is easily accessible from models &
shells.

EmailComponent is deprecated, because it
doesn’t really add anything at this point.
Simple Example
1   <?php
2   App::uses('CakeEmail', 'Network/Email');
3   $mail = new CakeEmail();
4   $mail->from('mark.story@gmail.com', 'Mark Story')
5       ->to('steve@apple.com', 'Steve Jobs')
6       ->subject('Love the new imacs')
7       ->send('I <3 you so much.');
Templates
 1   <?php
 2   App::uses('CakeEmail', 'Network/Email');
 3   $mail = new CakeEmail();
 4   $mail->from('mark.story@gmail.com', 'Mark Story')
 5       ->to('steve@apple.com', 'Steve Jobs')
 6       ->subject('Love the new imacs')
 7       ->template('love_you', 'simple')
 8       ->emailFormat('html')
 9       ->viewVars($vars)
10       ->send();
Mail Transports


Extracted out as separate classes.

3 built-in transports, and you can make your
own.
Testing
Testing

PHPUnit is the de-facto standard.

SimpleTest is less feature rich, and didn’t
have a PHP5 compatible version when we
started.

Tune in for my talk on PHPUnit.
Performance
All win
Lazy loading everywhere it made sense.

  Components, helpers, associated models.

Removed most getInstance() methods.

New conventions mean less Inflector calls.

Streamlined dispatch cycle.

Persistent dbo cache.
Hello World (rps)
350.0



262.5
                                         CakePHP 1.3.11
                                         CakePHP 2.0-beta
175.0



 87.5



   0
                 Hello world

        siege -b -c 20 -r 100 http://localhost/hello/world
Basic blog (rps)
50.0



37.5
                                      CakePHP 1.3.11
                                      CakePHP 2.0-beta
25.0



12.5



  0
              Basic blog

       siege -b -c 20 -r 100 http://localhost/posts
Functions called
                                       Hello World     Basic Blog
500



375



250



125



  0
       CakePHP 1.3.11                   CakePHP 2.0-beta
              Collected using webgrind and xdebug
Questions?

More Related Content

What's hot (20)

PDF
Introduction to puppet
Habeeb Rahman
 
PDF
Rspec API Documentation
SmartLogic
 
PDF
Master the New Core of Drupal 8 Now: with Symfony and Silex
Ryan Weaver
 
PDF
Puppet at GitHub / ChatOps
Puppet
 
PPTX
You are not_hiding_from_me_.net
Chung Wee Jing
 
PDF
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Ryan Weaver
 
PDF
Puppet at Pinterest
Puppet
 
PDF
Cooking Perl with Chef
David Golden
 
PDF
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
Matthias Noback
 
PDF
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
singingfish
 
PDF
Web develop in flask
Jim Yeh
 
PDF
Nginx pres
James Fuller
 
PDF
Writing Software not Code with Cucumber
Ben Mabey
 
PDF
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Ryan Weaver
 
PDF
parenscript-tutorial
tutorialsruby
 
PPT
Top 50 Interview Questions and Answers in CakePHP
Ketan Patel
 
PDF
Python tools for testing web services over HTTP
Mykhailo Kolesnyk
 
PDF
2 introduction-php-mvc-cakephp-m2-installation-slides
MasterCode.vn
 
PDF
Maven 3.0 at Øredev
Matthew McCullough
 
DOC
Debugging over tcp and http
Kaniska Mandal
 
Introduction to puppet
Habeeb Rahman
 
Rspec API Documentation
SmartLogic
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Ryan Weaver
 
Puppet at GitHub / ChatOps
Puppet
 
You are not_hiding_from_me_.net
Chung Wee Jing
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Ryan Weaver
 
Puppet at Pinterest
Puppet
 
Cooking Perl with Chef
David Golden
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
Matthias Noback
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
singingfish
 
Web develop in flask
Jim Yeh
 
Nginx pres
James Fuller
 
Writing Software not Code with Cucumber
Ben Mabey
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Ryan Weaver
 
parenscript-tutorial
tutorialsruby
 
Top 50 Interview Questions and Answers in CakePHP
Ketan Patel
 
Python tools for testing web services over HTTP
Mykhailo Kolesnyk
 
2 introduction-php-mvc-cakephp-m2-installation-slides
MasterCode.vn
 
Maven 3.0 at Øredev
Matthew McCullough
 
Debugging over tcp and http
Kaniska Mandal
 

Similar to Ch ch-changes cake php2 (20)

KEY
CakePHP 2.0 - PHP Matsuri 2011
Graham Weldon
 
PDF
CakePHP 3.0: Embracing the future
JosĂŠ Lorenzo RodrĂ­guez Urdaneta
 
PPT
Synapseindia reviews sharing intro cakephp
SynapseindiaComplaints
 
PDF
4 introduction-php-mvc-cakephp-m4-controllers-slides
MasterCode.vn
 
PPTX
Cake php
Jyotisankar Pradhan
 
ODP
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
David Yell
 
KEY
Really Rapid Admin Application Development
Jose Diaz-Gonzalez
 
PDF
Intro to CakePHP
Walther Lalk
 
DOC
How to migrate Cakephp 1.x to 2.x
Andolasoft Inc
 
PDF
CakePHP
Walther Lalk
 
PPTX
Ei cakephp
eiei lay
 
PPTX
Cakeph pppt
Wizard Rider
 
PDF
5503 cake php-tutorial-no-1-from-ibm
balajipala
 
PPT
Introduction to Cakephp
Aditya Mooley
 
KEY
Re-imaginging CakePHP
Graham Weldon
 
ODP
PHP South Coast - Don't code bake, an introduction to CakePHP 3
David Yell
 
PDF
Cake php cookbook
N.Raj Ganapathi
 
PDF
Cake Php 1.2 (Ocphp)
guest193fe1
 
KEY
CakePHP 2.0 - It'll rock your world
Graham Weldon
 
PPTX
cakephp UDUYKTHA (1)
Varsha Krishna
 
CakePHP 2.0 - PHP Matsuri 2011
Graham Weldon
 
CakePHP 3.0: Embracing the future
JosĂŠ Lorenzo RodrĂ­guez Urdaneta
 
Synapseindia reviews sharing intro cakephp
SynapseindiaComplaints
 
4 introduction-php-mvc-cakephp-m4-controllers-slides
MasterCode.vn
 
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
David Yell
 
Really Rapid Admin Application Development
Jose Diaz-Gonzalez
 
Intro to CakePHP
Walther Lalk
 
How to migrate Cakephp 1.x to 2.x
Andolasoft Inc
 
CakePHP
Walther Lalk
 
Ei cakephp
eiei lay
 
Cakeph pppt
Wizard Rider
 
5503 cake php-tutorial-no-1-from-ibm
balajipala
 
Introduction to Cakephp
Aditya Mooley
 
Re-imaginging CakePHP
Graham Weldon
 
PHP South Coast - Don't code bake, an introduction to CakePHP 3
David Yell
 
Cake php cookbook
N.Raj Ganapathi
 
Cake Php 1.2 (Ocphp)
guest193fe1
 
CakePHP 2.0 - It'll rock your world
Graham Weldon
 
cakephp UDUYKTHA (1)
Varsha Krishna
 
Ad

More from markstory (20)

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

Recently uploaded (20)

PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 

Ch ch-changes cake php2