PHP code example of mkiselev / yii2-serialize-attribute-behavior

1. Go to this page and download the library: Download mkiselev/yii2-serialize-attribute-behavior library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mkiselev / yii2-serialize-attribute-behavior example snippets


public function behaviors()
{
    return [
        ...
        [
            'class' => SerializeAttributeBehavior::className(),
            'attribute' => 'data',
            'unserializedAttributeSuffix' => 'Array',
        ],
        ...
    ];
}

public function behaviors()
{
    return [
        ...
        [
            'class' => SerializeAttributeBehavior::className(),
            'attribute' => 'data',
            'unserializedAttributeSuffix' => 'Model',
            // MyModel must extend mkiselev\serialized\Model
            'setAttributesToModel' => MyModel::className(),
            'setAttributesToModelSafeOnly' => true,
            // serializerClass must implements mkiselev\serialized\interfaces\SerializerInterface
            'serializerClass' => MySerializer::className(),
        ],
        ...
    ];
}

<?= $form->field($model, 'activeRecordModelAttribute')->textInput(); 

php composer.phar