Serializing Cactiverecord Object Behavior

Version 0.03

Fix 1 bugs.

Fix 1 issue : When we restore a object from serialized , value of attribute "id" is not set.

***Changelog version to 0.0.2 ***

  • Allow to choose options load safe attributes or not.

    +loadFromSerialized($serializedString = null, $safeOnly = false)

    +loadFromStorage(Array $params = array(), $storage = ‘session’, $safeOnly = false)

This behavior is used for serializing all attributes of a active-record. If you want to add some extended attributes to serialized data, you can implement method addDataToSerialized in the active-record or its behavior objects. And add method loadAddedDataFromSerialized for restoring active-record objects It also support store serialized data into session and restore from it.

  • Installing

    File main.php (config)






In active-record class

public function behaviors() {

         return array(

            'serialize' => array(

                'class' => 'ext.lotusbreath.model.serialize.LSerializeBehavior'




  • Usage:

  • get serialized data :

$post = Post::model()->findByPk(1);

     $serializedString =  $post->serializeData();

  • save serialized data into session

     $post->saveSerializedData(array('sesssionKey' => 'xxxx' ));

  • restore object from string


  • restore object from session dada

$post->loadFromStorage(array('sesssionKey' => 'xxxx' ));

  • Changelog :

    Version 0.0.1

    • Serialized all attribute values ( from $attributes property of active-record object)

    • Call function addDataToSerialized from a active-record object and its behaviors to add extended data that be also serialized

    • Call function loadAddedDataFromSerialized from a active-record object and its behaviors to restore extended data

Thanks for your efforts.Try to put it in wikki article.;)

Ok, thanks