26
Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo The New Year CakePHP Study in Tokyo

Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Story of CakePHP 2.0

2011.1.17

The New Year CakePHP Study in TokyoThe New Year CakePHP Study in Tokyo

Page 2: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

About Me

Name : Shimizu Hiroki(hiromi2424)

Job : Web Developer(Freelance)

Libraries : github(Transition, ModularAuth)

Work : Translation

Hobby : Singing, Beer!!!

Page 3: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

IntroductionIntroduction

Page 4: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

CakePHP 2.0 has large number of enhancements

It is no longer same thing compared with 1.x

But there are many compatible stuff

Most of libraries and applications also can be migrated easily

Introduction

Page 5: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Summary Decoupling & Delegeting

Request & Response Auth Loading Object On The Fly Others

Various Problems Resolved Security Component Pagination More Flexible Routes Lazy Loading

Conclusion

Page 6: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & DelegetingDecoupling & Delegeting

Page 7: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Current Requst handling

Request & Response

Lose ConsistencyHard to TestUgly WorkaroundImpossible to Inherit

Page 8: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Requst handling in CakePHP 2.0

Request & Response

Same ObjectCommon APIParse RequestConvenient Method

Page 9: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Request & Response

In Your Controller or so $this->request->here

$this->params['prefix'] // also accesible but deprecated

$this->request->data('User.name'); // returns name

$this->request->data('User.ip_address',$this->request->clientIp()

);

Page 10: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Response Handling in CakePHP 2.0

Request & Response

All of handling HTTP response would be done through Response object

Helps Media Rendering Download HTTP Systems

Page 11: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Auth's Responsibility was too heavy

Auth

Validating Post LoginLogin/Logout HandlingLoading Current UserVarious Autorization Pattern

DarkAuthOpenID and OAuth

Page 12: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Auth will be separated

Auth

Authentication and AuthorizationBasic, Digest Authentication is

already availableCore Team giving a try to support OpenID

Page 13: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

ObjectCollection is available

Loading Object On The Fly

In the past, there were similar patterns to

load kinds of ObjectComponents, helpers and tasks could not be

loaded dynamically

Now Collection pattern is gathered atObjectCollection

Page 14: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Common API for Collections

Loading Object On The Fly

ObjectCollection load() attached() trigger() other methods

Compatible methods like attach() is alsoavailable

Page 15: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Loading Object On The Fly

In Your Controller $this->Components->load('Cookie', array('name' => 'MyCookie'))

In Your Component $this->Auth = $this->_Collection->load('Auth');

In You View $this->Time = $this->loadHelper('Time'); // convenient alias $this->Time = $this->Helpers->load('Time');

In your Model $this->Behaviors->load('Containable'); $this->Behaviors->attach('Containable'); // compatible

Page 16: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Decoupling & Delegeting

Number of classes deletege

Others

Session Handler is now objectConfigure Reader is available You can load configurations as formated you prefer,

like YAML, XML, JSON

Error Handler and Exception Renderer cakeError() was used for simulation of Exception You can specify what handler is used in core config

Custom Object allows you to develop

advanced and freely

Page 17: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems ResolvedVarious Problems Resolved

Page 18: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

CSRF Protection enhancements

Securty Component

It was coupled with CSRF protection andform tampering safe-guards

Disabling CSRF protection meant disablingform tampering safe-guards also

It prevented generating dynamic form

These are now standalone

Page 19: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Multi-time token is available

Securty Component

There was only one-time tokenSometimes it was not useful

Now Security Component can beused practically

Page 20: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Pagination supports GET method

Pagination

Only parsing query string was supportedGenerating query string was not supported

Now GET method pagination is fully supported

Page 21: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

New Paginator Options

Pagination

$maxLimit Prevent $limit being too high value

$paramType 'querystring' can be used for GET method

'convertKeys' for PaginatorHelper::options() Allows other parameters to be included

Page 22: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Behavior can have pagination methods

Pagination

There was no way to make sure what

method is available through Behaviors

on your model Model::hasMethod() is implemented

Mostly same to model methods paginate() paginateCount()

Page 23: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Array can be used as a named arguments

More Flexible Routes

Router could not handle array as named

arguments Router::url(array('named' => array()));=> named:Array /named[hoge][piyo]:fuga=> array('named[hoge][piyo]' => 'fuga')

Now deep array can be used

Page 24: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Full url can be generated

More Flexible Routes

1.3's custom routes handle only relative urlfunction match($url) {

return '/users/login';}

2.x's custom routes can handle absolute urlfunction match($url) {

return 'https://auth.example.com/users/login';}

Page 25: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

Various Problems Resolved

Lazy Loading in sundry of places

Lazy Loading

Loading model costs too expensiveLazyModelCore supports lazy loading now Components Helpers Tasks Associated Models

Loading controller's component is not lazy

Page 26: Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

ConclusionConclusion

There are many and many other changes PHPUnit DataSource enahancements

Nesting Transaction Postgress support improved

Standardization for directory structure Static Session ... And so

Core team works hard to make compatible ways Why do you not use 2.0?