en story of cakephp2.0

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

Upload: hiroki-shimizu

Post on 24-May-2015

1.021 views

Category:

Technology


1 download

TRANSCRIPT

  • 1. Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo

2. AboutM e Name : ShimizuHiroki( hiromi2424 ) Job : WebDeveloper(Freelance) L ibraries : github ( Transition ,ModularAuth ) W ork : Translation H obby : S inging, Beer!!! 3. Introduction 4.

  • 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 5. Summary

  • Decoupling & Delegeting
    • Request & Response
    • Auth
    • Loading Object On The Fly
    • Others
  • Various Problems Resolved
    • Security Component
    • Pagination
    • More Flexible Routes
    • Lazy Loading
  • Conclusion

6. Decoupling & Delegeting 7. Decoupling & Delegeting

  • Current Requst handling

Request & Response

  • Lose Consistency
  • Hard to Test
  • Ugly Workaround
  • Impossible to Inherit

8. Decoupling & Delegeting

  • Requst handling in CakePHP 2.0

Request & Response

  • Same Object
  • Common API
  • Parse Request
  • Convenient Method

9. Decoupling & Delegeting

  • In Your Controller or so
  • $this-> request ->here
  • $this->params['prefix'] // also accesible butdeprecated
  • $this-> request -> data (' User.name '); // returns name
  • $this->request->data('User.ip_address',
      • $this-> request -> clientIp ()
  • );

Request & Response 10. Decoupling & Delegeting

  • Response Handling in CakePHP 2.0

Request & Response

  • All of handling HTTP response would bedone through Response object
  • Helps
    • Media Rendering
    • Download
    • HTTP Systems

11. Decoupling & Delegeting

  • Auth's Responsibility was too heavy

Auth

  • Validating Post Login
  • Login/Logout Handling
  • Loading Current User
  • Various Autorization Pattern
  • DarkAuth
  • OpenIDandOAuth

12. Decoupling & Delegeting

  • Auth will be separated

Auth

  • AuthenticationandAuthorization
  • Basic ,DigestAuthentication is already available
  • Core Team giving a try to supportOpenID

13. Decoupling & Delegeting

  • ObjectCollection is available

Loading Object On The Fly

  • In the past, there were similarpattern s to load kinds of Object
  • Components, helpers and tasks could not be loadeddynamically
  • Now Collection pattern is gathered at ObjectCollection

14. Decoupling & Delegeting

  • Common API for Collections

Loading Object On The Fly

  • ObjectCollection
    • load()
    • attached()
    • trigger()
    • other methods
  • Compatible methods like attach() is also available

15. Decoupling & Delegeting

  • In YourController
  • $this->Components-> load ('Cookie', array('name' => 'MyCookie'))
  • In YourComponent
  • $this->Auth = $this-> _Collection -> load ('Auth');
  • In YouView
  • $this->Time = $this-> loadHelper ('Time'); // convenient alias
  • $this->Time = $this-> Helpers -> load ('Time');
  • In yourModel
  • $this->Behaviors-> load ('Containable');
  • $this->Behaviors->attach('Containable'); // compatible

Loading Object On The Fly 16. Decoupling & Delegeting

  • Number ofclasse s deletege

Others

  • Session Handler is now object
  • Configure Reader is available
    • You can load configurationsasformat ed you prefer , likeYAML ,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 Objectallows you to develop advanced and freely

17. Various Problems Resolved 18. Various Problems Resolved

  • CSRF Protection enhancements

Securty Component

  • It was coupled with CSRF protection and form tampering safe-guards
  • Disabling CSRF protection meant disabling form tampering safe-guardsalso
  • It prevented generatingdynamic form
  • These are now standalone

19. Various Problems Resolved

  • Multi-time token is available

Securty Component

  • There was only one-time token
  • Sometimes it was not useful
  • Now Security Component can be used practically

20. Various Problems Resolved

  • Pagination supports GET method

Pagination

  • Only parsing query string was supported
  • Generating query string was not supported
  • Now GET method pagination isfully supported

21. Various Problems Resolved

  • New Paginator Options

Pagination

  • $maxLimit
    • Prevent $limit beingtoo high value
  • $paramType
    • 'querystring' can be used for GET method
  • ' convertKeys ' for PaginatorHelper::options()
    • Allows other parameters to be included

22. Various Problems Resolved

  • Behavior can have pagination methods

Pagination

  • There was nowayto make sure whatmethod is available through Behaviorson your model
    • Model:: hasMethod () is implemented
  • Mostly same to model methods
    • paginate()
    • paginateCount()

23. Various Problems Resolved

  • Array can be used as anamed arguments

More Flexible Routes

  • Router could not handle array asnamed arguments
    • Router::url(array('named' => array()));
    • => named: Array
    • /named[hoge][piyo]:fuga
    • => array('named [hoge][piyo] ' => 'fuga')
  • Now deep array can be used

24. Various Problems Resolved

  • Full url can be generated

More Flexible Routes

  • 1. 3 's custom routes handle onlyrelativeurl
    • function match($url) {
      • return '/users/login';
    • }
  • 2.x's custom routes can handleabsoluteurl
    • function match($url) {
      • return ' https :// auth. example.com/users/login';
    • }

25. Various Problems Resolved

  • Lazy Loading in sundry of places

Lazy Loading

  • Loading modelcosts too expensive
  • LazyModel
  • Core supports lazy loading now
    • Components
    • Helpers
    • Tasks
    • Associated Models
  • Loading controller's component isnotlazy

26. Conclusion

  • There are many and manyotherchanges
    • PHPUnit
    • DataSource enahancements
      • Nesting Transaction
      • Postgress support improved
    • Standa r dizationfor directory structure
    • Static Session
    • ...And so
  • Core team works hard to make compatible ways
  • Why do you not use 2.0?