• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introducing CakeEntity
 

Introducing CakeEntity

on

  • 3,322 views

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

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

Statistics

Views

Total Views
3,322
Views on SlideShare
2,109
Embed Views
1,213

Actions

Likes
2
Downloads
6
Comments
0

12 Embeds 1,213

http://pneskin2.nekoget.com 545
http://pneskin2.nekoget.com 545
http://techtalk.nekoget.com 82
http://paper.li 20
http://slideclip.b-prep.com 6
http://webcache.googleusercontent.com 5
https://twitter.com 4
http://www.linkedin.com 2
http://us-w1.rockmelt.com 1
http://127.0.0.1 1
http://ss.dotbranch.com 1
http://us-w1.rockmelt.com 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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

Introducing CakeEntity Introducing CakeEntity Presentation Transcript

  • CakeEntityThe ActiveRecord for CakePHP @basuke https://github.com/kanshin/CakeEntity
  • • @basuke• Mac / iPhone / Newton• PHP : 10+ years
  • http://www.kanshin.com/ 2001AssistOn http://www.assiston.co.jp/ 2004 https://tabidachi.ana.co.jp/ 2006
  • CakeEntity• CakePHP• Active Record Model•• GitHub• https://github.com/kanshin/CakeEntity• CakePHP 1.3, PHP 5.2 >
  • CakeEntity•• CakePHP 1.3.11 1.3.12 up• Smarty Cake• CakeSmarty•
  • 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
  • Active Record
  • CakeEntity find$post = $this->Post->entity(); //$post->content = "Hello world!";$post->save(); //
  • CakeEntity• array() [ ]• • • •
  • Prepare
  • first things first entityapp/plugins/entity/ orplugins/entity/
  • EntityModel extendsApp::import(Model, Entity.EntityModel);class Post extends EntityModel { ...}
  • Find
  • entity => true$this->Post->find(all, array( conditions => ... order => ... entity => true,));
  • $result = [ {id: 1, title:"title1", author_id:"123", ... } {id: 2, title:"title2", content:"...", } ...];// paginate()
  • // Post -> belongsTo -> Author$this->Post->find(all, array( conditions => ... contain => array(Author), entity => true,));
  • $result = [ {title:"title1", author: {id:3, name:"Basuke"}, ... } {title:"title2", author:null, ... } ...];//
  • hasMany // Post -> hasMany -> Image $this->Post->find(all, array( conditions => ... contain => array(Image), entity => true, ));
  • $result = [ {title:"title1", images: [ {path:"..."}, {path:"..."}] } {title:"title2", images: [{path:"..."}, ...] } ...];// w
  • load
  • $post = $this->Post->find(first, array( conditions => array(id=>$id), entity => true,)); or$post = $this->Post->entityById($id);
  • instantiation
  • $post = $this->Post->entity(); $post->title = “Hello”;• $post = new PostEntity();
  • Save
  • $post->title = "Hello world";$post->content = file_get_content(...);if ($post->save()) { $this->isCool();}
  • EntityEntityEntityModle Entity
  • Entity + Entity entityClass()
  • protected function entityClassForData($data) { switch ($data[‘type’]) { case ‘hyper’: return ‘HyperPostEntity’; default: return ‘PlainPostEntity’; }}
  • isHidden(), publish()
  • • $post->property_name• $post[‘property_name’]• $post->some_method()• $post[‘some_method’]•• []
  • {Smarty}• Smarty {$post.property_name}• ()••
  • public function allows() { return array(); }• allows()• public
  • public $comments; public function comments() { $Comment = $this->getModel()->Comment; return $Comment->find(array( ... )); }• $post[‘comments’]
  • CakePHP 2.0 w Many to Many
  • wREADME.md
  • Thankshttp://d.hatena.ne.jp/basuke/