Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/softmonkeyjapan/cakephp-objectify-behavior

ObjectifyBehavior for CakePHP 2.x. Transform regular array returned by the ORM into object
https://github.com/softmonkeyjapan/cakephp-objectify-behavior

Last synced: 5 days ago
JSON representation

ObjectifyBehavior for CakePHP 2.x. Transform regular array returned by the ORM into object

Awesome Lists containing this project

README

        

# Objectify Behavior (Plugin CakePHP)

ObjectifyBehavior aims to convert the usual array that CakePHP return ( e.g, find() ) into an object.

## Requirements

* CakePHP 2.x
* PHP5

## Installation

_[Manual]_

* Download this: [https://github.com/SoftMonkeyJapan/ObjectifyBehavior/archive/master.zip](https://github.com/SoftMonkeyJapan/ObjectifyBehavior/archive/master.zip)
* Unzip that download.
* Go into the unzip folder
* Copy the file `ObjectifyBehavior.php` to `Models/Behaviors`

_[GIT Clone]_

In your `Models/Behaviors` directory type:

```bash
git clone -b master git://github.com/SoftMonkeyJapan/ObjectifyBehavior.git
cp ObjectifyBehavior/ObjectifyBehavior.php ./ObjectifyBehavior.php
```

## Usage

### Initialization

Go into your model :

```php
Post->objectify(true); // Enable
$this->Post->objectify(false); // Disable
}
}
```

And that's all. You're now good to go. You can simply access the attributes as an object :

```php
Post->objectify(true);

// Find first
$post = $this->Post->find('first');
echo $post->name;

// Example with a find all
$posts = $this->Post->find('all');
foreach ($posts as $post)
{
echo $post->name;
echo $post->content;
}
}
}
```

## License

You are allowed to use it for whatever you want and whenever you want.