Skip to content

kanshin/CakeEntity

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

What is CakeEntity?

  • find() now returns array of objects instead of array of arrays.
  • Plugin for CakePHP
  • 100% compatible with the standard Model.
  • Open source. Available in GitHub. MIT Lisense.
  • CakePHP 1.3, PHP 5.2 >

https://github.com/kanshin/CakeEntity

Installation

Clone in plugin directory with name entity:

git clone git://github.com/kanshin/CakeEntity.git plugins/entity

Or download an archive and extract in plugins/entity.

How to use

CakeEntity don't change anything with just the installation. You have to enables the functionality by indicating to use it. This is for compati- bility reason.

Use EntityModel as the super class of models where you want to activate.

App::import('Model', 'Entity.EntityModel');

class Post extends EntityModel {
    ...

Then in the options of the find, specify entity => true:

$entity = $this->Post->find('all', array(
    'conditions' => ...
    'order' => ...
    'entity' => true, 
));

Now the $result includes the array of objects (entities).

Entity class

Entity class is the default class used as the result of objects. If there is a class with the model's name + 'Entity', that class is uses instead. (i.e. For model "Post", the class "PostEntity" is used)

Array access for Entity object

Entity's property can be accessed using array syntax.

echo $post['title']; // == $post->title

Array access is vest suited with using with Smarty.

Hello, my name is {$post.author.name|h}.

Also array access introduces two important feature:

  • access controll for security.
  • cache for performance.

For more information

Introducing CakeEntity (PHP study in Tokyo 10/1/2011)

About

CakePHP model extension. With this plugin, your data is no longer just an array of data, but the real object. Works with CakePHP 1.3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages