yii2-json-behavior
yii2-json-behavior copied to clipboard
Default value for initialization
Shouldn't it be property to define default value for JsonField? For example
<?php
class Model extends ActiveRecord {
public function behaviors() {
return ['json' => [
'class' => JsonBehavior::class,
'attributes' => 'settings',
'default' => ['key' => 'value],
];
}
}
I need it because I may use settings before validation, so I cant use default validator and need to create own behavior that do initialization. If you want I can create PR.
Why do not you use the value when initializing?
class Model extends ActiveRecord {
public function behaviors() {
return ['json' => [
'class' => JsonBehavior::class,
'attributes' => 'settings',
];
}
public function init()
{
$this->settings = new JsonField(['key' => 'value']);
}
}
Default in configuration is more friendly. Anyway, after 2.0.14 yii release I do not use this library because of built in json support