ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
CakeEntity
The ActiveRecord
     for CakePHP
        Basuke Suzuki @basuke
  https://github.com/kanshin/CakeEntity
me

? Basuke Suzuki @basuke
? Mac / iPhone / Newton
? PHP : 10+ years
What is CakeEntity?
?   Plugin for CakePHP
?   Support ActiveRecord in Model
?   100% compatible with the standard Model.
?   Open source. Available in GitHub
?   https://github.com/kanshin/CakeEntity
?   CakePHP 1.3, PHP 5.2 >
Active Record

ActiveRecord is "an object that wraps a row in a

database table or view, encapsulates database

access and adds domain logic on that data".

                                     Fowler, 2003
         http://www.martinfowler.com/books.html
Cons.

 ?nd() returns array of object.
 You can manipulate object immediately, directly.

$post = $this->Post->entity(); // creation
$post->content = "Hello world!";
$post->save();
Cons. cont.

? Less array() and [ brankets ].
? Makes code structure simple.
  ? Safe access to domain logic from View.
  ? More code moves from Helper to Model.
  ? More code moves from Controller to Model.
? Testable.
Prepare
?rst things ?rst

Place in the plugins directory.
Name should be ¡°Entity¡±.

app/plugins/entity/
   or
plugins/entity/
Extends EntityModel

App::import('Model', 'Entity.EntityModel');
class Post extends EntityModel {
   ...
}
Find
'entity' => true

$this->Post->?nd('all', array(
      'conditions' => ...
      'order' => ...
      'entity' => true,
));
Result is array of
         object
                                                    

$result = [
   {id: 1, title:"title1", author_id:"123", ... }
   {id: 2, title:"title2", content:"...", }
   ...
];

// works ?ne with paginate()
Works with
           ¡°belongsTo¡±
// Post -> belongsTo -> Author
$this->Post->?nd('all', array(
      'conditions' => ...
      'contain' => array('Author'),
      'entity' => true,
));
Property is also Entity

 $result = [
     {title:"title1", author: {id:3,
     name:"Basuke"}, ... }
     {title:"title2", author:null, ... }
     ...
 ];
 // property name is converted to lower case
Of course, works with
     ¡°hasMany¡±
// Post -> hasMany -> Image
$this->Post->?nd('all', array(
      'conditions' => ...
      'contain' => array('Image'),
      'entity' => true,
));
Property holds array
     of Entity
$result = [
    {title:"title1", images: [ {path:"..."},
    {path:"..."}] }
    {title:"title2", images: [{path:"..."}, ...] }
    ...
];
// property name is pluralized.
load
Fetch one entity
$post = $this->Post->?nd('?rst', array(
       'conditions' => array('id'=>$id),
       'entity' => true,
));
      or
$post = $this->Post->entityById($id);
instantiation.
Instantiation is easy

  $post = $this->Post->entity();
  $post->title = ¡°Hello¡±;

? Don¡¯t use ¡°new¡±. PostEntity class has no
  information of model.
  $post = new PostEntity();
Save
Save is easy.

$post->title = "Hello world";
$post->content = ?le_get_content(...);
if ($post->save()) {
    $this->isCool();
}
Entity Class

Entity Class is a default class when EntityModel
will instantiate object.
Customizable with sub class of Entity.
Many features to works with View layer.
The result of method call can be cached.
Property access can be restricted.
Entity Subclass
If class with model¡¯s name + ¡°Entity¡± is exists, that
class is used instead.

class PostEntity extends Entity {

 ...
}

Or override entityClass().
Custom subclass
  depending by data
protected function entityClassForData($data) {

 switch ($data[¡®type¡¯]) {

 
 case ¡®hyper¡¯:

 
 
 return ¡®HyperPostEntity¡¯;

 
 default:

 
 
 return ¡®PlainPostEntity¡¯;

 }
}
Domain logic can be
placed in Entity subclass

 Object is the place of domain logic.

 Method for collection should be placed in Model.
 Method for record should be placed in Entity.
   ex) isHidden(), publish() is the candidates.
Easy access for
 property and method
? For $post->property_name
  ? $post[¡®property_name¡¯] is OK
? For $post->some_method()
  ? $post[¡®some_method¡¯] is also OK
? Array access is cacheable.

? Wait! I want to increase [ ] any more! Why?
{Smarty} uses ¡°.¡±


? Smarty uses dot to access array.
  ? i.e {$post.property_name}
? Also reduce ( ) for method access.
? Easier code reading.
Method access control
  
 public function allows() {
  
 
 return array();
  
 }

? Override allows(). Return name of method to
  allow access.

? Or de?ne public method.
Result is cached
          automatically
    public $comments;
    public function comments() {
    
 $Comment = $this->getModel()->Comment;
    
 return $Comment->?nd(array(
    
 
 ...
    
 ));
    }

?   $post[¡®comments¡¯] is cached.
Future

CakePHP 2.0, of course.
Reverse conversion to array structure.
More tests.
saveAll() support.
dirty property detection.
Document is


not ready. Sorry.
Sample is available soon.
Thanks




http://d.hatena.ne.jp/basuke/

More Related Content

What's hot (20)

Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
Jos¨¦ Lorenzo Rodr¨ªguez Urdaneta
?
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
ichikaway
?
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
Nate Abele
?
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
?
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
Nate Abele
?
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
G Woo
?
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
Fabien Potencier
?
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
?
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
Nate Abele
?
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
?
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
?
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
?
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
?
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
Nicolas Carlo
?
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
?
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
Azim Kurt
?
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
?
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Rifat Nabi
?
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
Inbal Geffen
?
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
Stephan Hochd?rfer
?
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
ichikaway
?
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
Nate Abele
?
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
?
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
Nate Abele
?
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
G Woo
?
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
Fabien Potencier
?
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
?
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
Nate Abele
?
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
?
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
?
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
?
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
Nicolas Carlo
?
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
?
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
Azim Kurt
?
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
?
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Rifat Nabi
?

Viewers also liked (6)

CoAP Talk
CoAP TalkCoAP Talk
CoAP Talk
Basuke Suzuki
?
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
Basuke Suzuki
?
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
Basuke Suzuki
?
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
Basuke Suzuki
?
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Toshiro Shimizu
?
³Õ³Ü±ð.Âá²õÈëÃÅ
³Õ³Ü±ð.Âá²õÈëÃųճܱð.Âá²õÈëÃÅ
³Õ³Ü±ð.Âá²õÈëÃÅ
Takuya Sato
?
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
³õ¤á¤Æ¤Î…gÌå¥Æ¥¹¥È
Basuke Suzuki
?
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
¾±°¿³§4ʱ´ú¤ÎλÖÃÇ鱨¥µ©`¥Ó¥¹¤Îʹ¤¤·½
Basuke Suzuki
?
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
±Ê´Ç²õ³Ù²µ°ù±ð³§²Ï³¢¤«¤é²Ñ´Ç²Ô²µ´Ç¶Ùµþ¤Ø
Basuke Suzuki
?
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Vue.js 2.0¤òÔ‡¤·¤Æ¤ß¤¿
Toshiro Shimizu
?
³Õ³Ü±ð.Âá²õÈëÃÅ
³Õ³Ü±ð.Âá²õÈëÃųճܱð.Âá²õÈëÃÅ
³Õ³Ü±ð.Âá²õÈëÃÅ
Takuya Sato
?

Similar to Introducing CakeEntity (20)

PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown Parts
Bastian Feder
?
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
Elizabeth Smith
?
OOP in PHP.pptx
OOP in PHP.pptxOOP in PHP.pptx
OOP in PHP.pptx
switipatel4
?
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
Barang CK
?
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
iKlaus
?
Oops in php
Oops in phpOops in php
Oops in php
Gourishankar R Pujar
?
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
Chhom Karath
?
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
?
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
?
Unittests f¨¹r Dummies
Unittests f¨¹r DummiesUnittests f¨¹r Dummies
Unittests f¨¹r Dummies
Lars Jankowfsky
?
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
?
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
Samuel ROZE
?
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
Michelangelo van Dam
?
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
?
php2.pptx
php2.pptxphp2.pptx
php2.pptx
ElieNGOMSEU
?
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
Piotr Pasich
?
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
?
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
DrupalCamp Kyiv
?
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
Jonathan Wage
?
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti
?
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown Parts
Bastian Feder
?
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
Elizabeth Smith
?
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
Barang CK
?
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
iKlaus
?
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
?
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
?
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
Samuel ROZE
?
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
Michelangelo van Dam
?
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
?
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
Piotr Pasich
?
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
?
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
Jonathan Wage
?
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti
?

Recently uploaded (20)

A Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin EngineeringA Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin Engineering
Daniel Lehner
?
Endpoint Backup: 3 Reasons MSPs Ignore It
Endpoint Backup: 3 Reasons MSPs Ignore ItEndpoint Backup: 3 Reasons MSPs Ignore It
Endpoint Backup: 3 Reasons MSPs Ignore It
MSP360
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)
nick896721
?
Gojek Clone Multi-Service Super App.pptx
Gojek Clone Multi-Service Super App.pptxGojek Clone Multi-Service Super App.pptx
Gojek Clone Multi-Service Super App.pptx
V3cube
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarterQ4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
MariaBarbaraPaglinaw
?
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
L01 Introduction to Nanoindentation - What is hardness
L01 Introduction to Nanoindentation - What is hardnessL01 Introduction to Nanoindentation - What is hardness
L01 Introduction to Nanoindentation - What is hardness
RostislavDaniel
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Stronger Together: Combining Data Quality and Governance for Confident AI & A...Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Precisely
?
Cloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in AviationCloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in Aviation
Assem mousa
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
Unlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤EUnlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤E
Expeed Software
?
Fl studio crack version 12.9 Free Download
Fl studio crack version 12.9 Free DownloadFl studio crack version 12.9 Free Download
Fl studio crack version 12.9 Free Download
kherorpacca127
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?
A Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin EngineeringA Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin Engineering
Daniel Lehner
?
Endpoint Backup: 3 Reasons MSPs Ignore It
Endpoint Backup: 3 Reasons MSPs Ignore ItEndpoint Backup: 3 Reasons MSPs Ignore It
Endpoint Backup: 3 Reasons MSPs Ignore It
MSP360
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)
nick896721
?
Gojek Clone Multi-Service Super App.pptx
Gojek Clone Multi-Service Super App.pptxGojek Clone Multi-Service Super App.pptx
Gojek Clone Multi-Service Super App.pptx
V3cube
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarterQ4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
MariaBarbaraPaglinaw
?
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
L01 Introduction to Nanoindentation - What is hardness
L01 Introduction to Nanoindentation - What is hardnessL01 Introduction to Nanoindentation - What is hardness
L01 Introduction to Nanoindentation - What is hardness
RostislavDaniel
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Stronger Together: Combining Data Quality and Governance for Confident AI & A...Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Stronger Together: Combining Data Quality and Governance for Confident AI & A...
Precisely
?
Cloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in AviationCloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in Aviation
Assem mousa
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
Unlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤EUnlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤E
Expeed Software
?
Fl studio crack version 12.9 Free Download
Fl studio crack version 12.9 Free DownloadFl studio crack version 12.9 Free Download
Fl studio crack version 12.9 Free Download
kherorpacca127
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?

Introducing CakeEntity

  • 1. CakeEntity The ActiveRecord for CakePHP Basuke Suzuki @basuke https://github.com/kanshin/CakeEntity
  • 2. me ? Basuke Suzuki @basuke ? Mac / iPhone / Newton ? PHP : 10+ years
  • 3. What is CakeEntity? ? Plugin for CakePHP ? Support ActiveRecord in Model ? 100% compatible with the standard Model. ? Open source. Available in GitHub ? https://github.com/kanshin/CakeEntity ? CakePHP 1.3, PHP 5.2 >
  • 4. Active Record ActiveRecord is "an object that wraps a row in a database table or view, encapsulates database access and adds domain logic on that data". Fowler, 2003 http://www.martinfowler.com/books.html
  • 5. Cons. ?nd() returns array of object. You can manipulate object immediately, directly. $post = $this->Post->entity(); // creation $post->content = "Hello world!"; $post->save();
  • 6. Cons. cont. ? Less array() and [ brankets ]. ? Makes code structure simple. ? Safe access to domain logic from View. ? More code moves from Helper to Model. ? More code moves from Controller to Model. ? Testable.
  • 8. ?rst things ?rst Place in the plugins directory. Name should be ¡°Entity¡±. app/plugins/entity/ or plugins/entity/
  • 10. Find
  • 11. 'entity' => true $this->Post->?nd('all', array( 'conditions' => ... 'order' => ... 'entity' => true, ));
  • 12. Result is array of object $result = [ {id: 1, title:"title1", author_id:"123", ... } {id: 2, title:"title2", content:"...", } ... ]; // works ?ne with paginate()
  • 13. Works with ¡°belongsTo¡± // Post -> belongsTo -> Author $this->Post->?nd('all', array( 'conditions' => ... 'contain' => array('Author'), 'entity' => true, ));
  • 14. Property is also Entity $result = [ {title:"title1", author: {id:3, name:"Basuke"}, ... } {title:"title2", author:null, ... } ... ]; // property name is converted to lower case
  • 15. Of course, works with ¡°hasMany¡± // Post -> hasMany -> Image $this->Post->?nd('all', array( 'conditions' => ... 'contain' => array('Image'), 'entity' => true, ));
  • 16. Property holds array of Entity $result = [ {title:"title1", images: [ {path:"..."}, {path:"..."}] } {title:"title2", images: [{path:"..."}, ...] } ... ]; // property name is pluralized.
  • 17. load
  • 18. Fetch one entity $post = $this->Post->?nd('?rst', array( 'conditions' => array('id'=>$id), 'entity' => true, )); or $post = $this->Post->entityById($id);
  • 20. Instantiation is easy $post = $this->Post->entity(); $post->title = ¡°Hello¡±; ? Don¡¯t use ¡°new¡±. PostEntity class has no information of model. $post = new PostEntity();
  • 21. Save
  • 22. Save is easy. $post->title = "Hello world"; $post->content = ?le_get_content(...); if ($post->save()) { $this->isCool(); }
  • 23. Entity Class Entity Class is a default class when EntityModel will instantiate object. Customizable with sub class of Entity. Many features to works with View layer. The result of method call can be cached. Property access can be restricted.
  • 24. Entity Subclass If class with model¡¯s name + ¡°Entity¡± is exists, that class is used instead. class PostEntity extends Entity { ... } Or override entityClass().
  • 25. Custom subclass depending by data protected function entityClassForData($data) { switch ($data[¡®type¡¯]) { case ¡®hyper¡¯: return ¡®HyperPostEntity¡¯; default: return ¡®PlainPostEntity¡¯; } }
  • 26. Domain logic can be placed in Entity subclass Object is the place of domain logic. Method for collection should be placed in Model. Method for record should be placed in Entity. ex) isHidden(), publish() is the candidates.
  • 27. Easy access for property and method ? For $post->property_name ? $post[¡®property_name¡¯] is OK ? For $post->some_method() ? $post[¡®some_method¡¯] is also OK ? Array access is cacheable. ? Wait! I want to increase [ ] any more! Why?
  • 28. {Smarty} uses ¡°.¡± ? Smarty uses dot to access array. ? i.e {$post.property_name} ? Also reduce ( ) for method access. ? Easier code reading.
  • 29. Method access control public function allows() { return array(); } ? Override allows(). Return name of method to allow access. ? Or de?ne public method.
  • 30. Result is cached automatically public $comments; public function comments() { $Comment = $this->getModel()->Comment; return $Comment->?nd(array( ... )); } ? $post[¡®comments¡¯] is cached.
  • 31. Future CakePHP 2.0, of course. Reverse conversion to array structure. More tests. saveAll() support. dirty property detection.
  • 32. Document is not ready. Sorry. Sample is available soon.

Editor's Notes