cserializebehavior Automatically serialize/unserialize model attributes.

  1. Requirements
  2. Usage
  3. Resources

This extension allows you to treat model attributes as arrays, and they are automatically serialized for insertion and unserialized upon select, as long as you use the active record find methods.

Requirements

Yii 1.1 or above

Usage

Just add the behavior to your behaviors list in your model (after placing the behavior in your app.behaviors folder)

In your model:

public function behaviors()
{
    return array(
          'CSerializeBehavior' => array(
               'class' => 'application.behaviors.CSerializeBehavior',
               'serialAttributes' => array('attribute_to_serialize'), // name of attribute(s)
           )
    );
}

And then you can use your attributes like this:

$m = new MyModel;
$m->attribute_to_serialize = array(...);
$m->save();

$m = MyModel::model()->findByPk(...);
$a = $m->attribute_to_serialize;
echo is_array($a); // should be true

Resources

6 0
8 followers
979 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Database
Developed by: nsbucky
Created on: Dec 28, 2010
Last updated: 13 years ago

Downloads

show all

Related Extensions