260 likes | 418 Views
2011.1.17 The New Year CakePHP Study in Tokyo. Story of CakePHP 2.0. About Me. Introduction. Introduction. CakePHP 2.0 has large number of enhancements It is no longer same thing compared with 1.x But there are many compatible stuff
E N D
2011.1.17 The New Year CakePHP Study in Tokyo Story of CakePHP 2.0
Introduction • 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
Summary • Decoupling & Delegeting • Request & Response • Auth • Loading Object On The Fly • Others • Various Problems Resolved • Security Component • Pagination • More Flexible Routes • Lazy Loading • Conclusion
Decoupling & Delegeting Request & Response Current Requst handling • Lose Consistency • Hard to Test • Ugly Workaround • Impossible to Inherit
Decoupling & Delegeting Request & Response Requst handling in CakePHP 2.0 • Same Object • Common API • Parse Request • Convenient Method
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() );
Decoupling & Delegeting Request & Response Response Handling in CakePHP 2.0 • All of handling HTTP response would be done through Response object • Helps • Media Rendering • Download • HTTP Systems
Decoupling & Delegeting Auth Auth's Responsibility was too heavy • Validating Post Login • Login/Logout Handling • Loading Current User • Various Autorization Pattern • DarkAuth • OpenID and OAuth
Decoupling & Delegeting Auth Auth will be separated • Authentication and Authorization • Basic, Digest Authentication isalready available • Core Team giving a try to support OpenID
Decoupling & Delegeting Loading Object On The Fly ObjectCollection is available • In the past, there were similar patterns toload kinds of Object • Components, helpers and tasks could not beloaded dynamically • Now Collection pattern is gathered atObjectCollection
Decoupling & Delegeting Loading Object On The Fly Common API for Collections • ObjectCollection • load() • attached() • trigger() • other methods • Compatible methods like attach() is alsoavailable
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
Decoupling & Delegeting Others Number of classes deletege • Session Handler is now object • Configure 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
Various Problems Resolved Securty Component CSRF Protection enhancements • It was coupled with CSRF protection andform tampering safe-guards • Disabling CSRF protection meant disablingform tampering safe-guardsalso • It prevented generating dynamic form • These are now standalone
Various Problems Resolved Securty Component Multi-time token is available • There was only one-time token • Sometimes it was not useful • Now Security Component can beused practically
Various Problems Resolved Pagination Pagination supports GET method • Only parsing query string was supported • Generating query string was not supported • Now GET method pagination is fully supported
Various Problems Resolved Pagination New Paginator Options • $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
Various Problems Resolved Pagination Behavior can have pagination methods • 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()
Various Problems Resolved More Flexible Routes Array can be used as a named arguments • 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
Various Problems Resolved More Flexible Routes Full url can be generated • 1.3's custom routes handle only relative url function match($url) { return '/users/login'; } • 2.x's custom routes can handle absolute url function match($url) { return 'https://auth.example.com/users/login'; }
Various Problems Resolved Lazy Loading Lazy Loading in sundry of places • Loading model costs too expensive • LazyModel • Core supports lazy loading now • Components • Helpers • Tasks • Associated Models • Loading controller's component is not lazy
Conclusion • 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?