Weitere ähnliche Inhalte Ähnlich wie Introducing CakeEntity (20) Mehr von Basuke Suzuki (6) Kürzlich hochgeladen (20) Introducing CakeEntity2. • @basuke
• Mac / iPhone / Newton
• PHP : 10+ years
4. CakeEntity
• CakePHP
• Active Record Model
•
• GitHub
• https://github.com/kanshin/CakeEntity
• CakePHP 1.3, PHP 5.2 >
6. 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
12. EntityModel extends
App::import('Model', 'Entity.EntityModel');
class Post extends EntityModel {
...
}
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
25. $post->title = "Hello world";
$post->content = file_get_content(...);
if ($post->save()) {
$this->isCool();
}
27. Entity + Entity
entityClass()
30. • $post->property_name
• $post[‘property_name’]
• $post->some_method()
• $post[‘some_method’]
•
• []
33. public $comments;
public function comments() {
$Comment = $this->getModel()->Comment;
return $Comment->find(array(
...
));
}
• $post[‘comments’]
Hinweis der Redaktion \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