2017 © Pedro Peláez
 

cakephp-plugin cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

image

imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  • Tuesday, June 23, 2015
  • by imsamurai
  • Repository
  • 1 Watchers
  • 13 Stars
  • 6,464 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

API Documentation

Check out Serializable Behavior API Documentation, (*1)

Abstract

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Serializable Behaviour for CakePHP 2.1+, (*3)

Use it if you want to save and read serialized data into db., (*4)

Installation

cd my_cake_app/app
git clone git://github.com/imsamurai/cakephp-serializable-behaviour.git Plugin/Serializable

or if you use git add as submodule:, (*5)

cd my_cake_app
git submodule add "git://github.com/imsamurai/cakephp-serializable-behaviour.git" "app/Plugin/Serializable"

then add plugin loading in Config/bootstrap.php, (*6)

CakePlugin::load('Serializable');

Configuration

Write global config if you need to use custom serialization function:, (*7)

Configure::write('Serializable', array(
  'serialize' => <valid callable>,
  'unserialize' => <valid callable>
));

Attach behaviour to model:, (*8)

public $actsAs = array(
      'Serializable.Serializable' => array(
        'fields' => <array of field names>,
        'serialize' => <valid callable>, // optional
        'unserialize' => <valid callable> // optional
        'merge' => true // optional
      )
);

By default serialization uses function serialize, unserialization - unserialize Merging is off by default, turning it on will do a recursive merge on existing records so you can add data without replacing the entire serialized object., (*9)

Advanced usage

If you want to use serialization with Containable behaviour you must modify your AppModel. For example we have 3 models that extedned AppModel: NewsPopular has many NewsPopularItem NewsPopularItem belongs to Article, (*10)

NewsPopularItem and Article has some serialized fields., (*11)

Assume you want to fetch data this way:, (*12)

$this->NewsPopular->contain(array(
        'NewsPopularItem' => array(
            'Article'
        )
    ));
$data = $this->NewsPopular->find('first');

In this case you must add some configuration to AppModel::afterFind. In basic case there must be:, (*13)

public function afterFind($results, $primary = false) {
    if (!$primary && $this->Behaviors->enabled('Serializable')) {
        return $this->Behaviors->Serializable->afterFind($this, $results, $primary);
    }
    return parent::afterFind($results, $primary);
}

And that's all! Now you have data structure with unserialized fields., (*14)

The Versions

23/06 2015

dev-master

9999999-dev http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

23/06 2015

1.0.6

1.0.6.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

23/06 2015

1.0.5

1.0.5.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

23/06 2015

1.0.4

1.0.4.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

23/06 2015

1.0.3

1.0.3.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

19/09 2014

1.0.2

1.0.2.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

07/02 2014

1.0.1

1.0.1.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour

18/01 2014

1.0.0

1.0.0.0 http://github.com/imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

  Sources   Download

MIT

The Requires

 

database cakephp serializable behaviour