Copies values to attributes from other attributes
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist platx/yii2-copy-attributes-behavior "*"
or add
"platx/yii2-copy-attributes-behavior": "*"
to the require section of your composer.json
file.
Once the extension is installed, simply use it in your ActiveRecord by :
public function behaviors()
{
return [
'copy-attributes' => [
'class' => '\platx\copyattributes\CopyAttributesBehavior',
'clearTags' => true,
'maxLength' => 160,
'attributes' => [
'share_title' => 'name',
'share_content' => 'content_short',
],
]
];
}
clearTags
: boolean, It determines whether to clear the attribute of html tags. Defaults to false
.maxLength
: integer, Trim the text to the specified length. Defaults to false
.attributes
: array, Array of attributes ( target attribute => source attribute). Defaults to null
:'attributes' => [
'target_attribute' => 'source_attribute',
'target_attribute2' => 'source_attribute2',
...
],
No stable releases.
Comments