platx / yii2-copy-attributes-behavior
Copies values to attributes from other attributes
Installs: 2 104
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2020-10-16 21:08:28 UTC
README
Copies values to attributes from other attributes
Installation
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.
Usage
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', ], ] ]; }
Behavior configuration
clearTags
: boolean, It determines whether to clear the attribute of html tags. Defaults tofalse
.maxLength
: integer, Trim the text to the specified length. Defaults tofalse
.attributes
: array, Array of attributes ( target attribute => source attribute). Defaults tonull
:
'attributes' => [ 'target_attribute' => 'source_attribute', 'target_attribute2' => 'source_attribute2', ... ],