platx / yii2-copy-attributes-behavior
此包已被弃用,不再维护。未建议替代包。
将值从其他属性复制到属性中
dev-master
2015-11-13 15:55 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2020-10-16 21:08:28 UTC
README
将值从其他属性复制到属性中
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist platx/yii2-copy-attributes-behavior "*"
或者
"platx/yii2-copy-attributes-behavior": "*"
将以下内容添加到您的 composer.json
文件的 require 部分。
使用方法
扩展安装完成后,只需在您的 ActiveRecord 中使用它即可
public function behaviors() { return [ 'copy-attributes' => [ 'class' => '\platx\copyattributes\CopyAttributesBehavior', 'clearTags' => true, 'maxLength' => 160, 'attributes' => [ 'share_title' => 'name', 'share_content' => 'content_short', ], ] ]; }
行为配置
clearTags
: 布尔型,它决定是否清除属性的 HTML 标签。默认为false
。maxLength
: 整数,将文本裁剪到指定的长度。默认为false
。attributes
: 数组,属性数组(目标属性 => 源属性)。默认为null
'attributes' => [ 'target_attribute' => 'source_attribute', 'target_attribute2' => 'source_attribute2', ... ],