yii2-extension yii2-serialize-attributes
This behavior 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.
wowkaster/yii2-serialize-attributes
This behavior 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.
- Sunday, March 1, 2015
- by wowkaster
- Repository
- 1 Watchers
- 2 Stars
- 771 Installations
- PHP
- 2 Dependents
- 0 Suggesters
- 1 Forks
- 0 Open issues
- 1 Versions
- 4 % Grown
yii2-serialize-attributes
Install, (*1)
require : {
"wowkaster/yii2-serialize-attributes": "dev-master"
}
How to use., (*2)
class SomeModel extends \yii\db\ActiveRecord {
public functuin rules() {
return [
[['options'], 'safe']
];
}
....
public function behaviors() {
return [
[
'class' => SerializeAttributesBehavior::className(),
'convertAttr' => ['options' => 'json']
]
];
}
====// OR //====
public function behaviors() {
return [
[
'class' => SerializeAttributesBehavior::className(),
'convertAttr' => ['options' => 'serialize']
]
];
}
}
$model = new SomeModel();
$model->options = ['value1', 'value2', 'param' => 'value'];
$model->save();
print_r($model->options); => Array('value1', 'value2', 'param' => 'value')
$model = SomeModel::findOne(1);
print_r($model->options); => Array('value1', 'value2', 'param' => 'value')
dev-master
9999999-dev
https://github.com/wowkaster/yii2-serialize-attributes
This behavior 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.
Sources
Download
MIT
The Requires
by
Vladikir Konchakovsky
yii2
serialize