Your SlideShare is downloading. ×

Introducing CakeEntity

3,228

Published on

CakePHPの検索でオブジェクトが返るようになるCakePHP用のプラグインの紹介

CakePHPの検索でオブジェクトが返るようになるCakePHP用のプラグインの紹介

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,228
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. CakeEntityThe ActiveRecord for CakePHP @basuke https://github.com/kanshin/CakeEntity
    • 2. • @basuke• Mac / iPhone / Newton• PHP : 10+ years
    • 3. http://www.kanshin.com/ 2001AssistOn http://www.assiston.co.jp/ 2004 https://tabidachi.ana.co.jp/ 2006
    • 4. CakeEntity• CakePHP• Active Record Model•• GitHub• https://github.com/kanshin/CakeEntity• CakePHP 1.3, PHP 5.2 >
    • 5. CakeEntity•• CakePHP 1.3.11 1.3.12 up• Smarty Cake• CakeSmarty•
    • 6. Active RecordActiveRecord is "an object that wraps a row in adatabase table or view, encapsulates databaseaccess and adds domain logic on that data". Fowler, 2003 http://www.martinfowler.com/books.html
    • 7. Active Record
    • 8. CakeEntity find$post = $this->Post->entity(); //$post->content = "Hello world!";$post->save(); //
    • 9. CakeEntity• array() [ ]• • • •
    • 10. Prepare
    • 11. first things first entityapp/plugins/entity/ orplugins/entity/
    • 12. EntityModel extendsApp::import(Model, Entity.EntityModel);class Post extends EntityModel { ...}
    • 13. Find
    • 14. entity => true$this->Post->find(all, array( conditions => ... order => ... entity => true,));
    • 15. $result = [ {id: 1, title:title1, author_id:123, ... } {id: 2, title:title2, content:..., } ...];// paginate()
    • 16. // Post - belongsTo - Author$this-Post-find(all, array( conditions = ... contain = array(Author), entity = true,));
    • 17. $result = [ {title:title1, author: {id:3, name:Basuke}, ... } {title:title2, author:null, ... } ...];//
    • 18. hasMany // Post - hasMany - Image $this-Post-find(all, array( conditions = ... contain = array(Image), entity = true, ));
    • 19. $result = [ {title:title1, images: [ {path:...}, {path:...}] } {title:title2, images: [{path:...}, ...] } ...];// w
    • 20. load
    • 21. $post = $this-Post-find(first, array( conditions = array(id=$id), entity = true,)); or$post = $this-Post-entityById($id);
    • 22. instantiation
    • 23. $post = $this-Post-entity(); $post-title = “Hello”;• $post = new PostEntity();
    • 24. Save
    • 25. $post-title = Hello world;$post-content = file_get_content(...);if ($post-save()) { $this-isCool();}
    • 26. EntityEntityEntityModle Entity
    • 27. Entity + Entity entityClass()
    • 28. protected function entityClassForData($data) { switch ($data[‘type’]) { case ‘hyper’: return ‘HyperPostEntity’; default: return ‘PlainPostEntity’; }}
    • 29. isHidden(), publish()
    • 30. • $post-property_name• $post[‘property_name’]• $post-some_method()• $post[‘some_method’]•• []
    • 31. {Smarty}• Smarty {$post.property_name}• ()••
    • 32. public function allows() { return array(); }• allows()• public
    • 33. public $comments; public function comments() { $Comment = $this-getModel()-Comment; return $Comment-find(array( ... )); }• $post[‘comments’]
    • 34. CakePHP 2.0 w Many to Many
    • 35. wREADME.md
    • 36. Thankshttp://d.hatena.ne.jp/basuke/

    ×