indifferend / yii2-behaviors
为Yii Framework 2.0收集的有用行为
2.1
2021-06-02 11:32 UTC
Requires
- php: ^7.1.8
- nesbot/carbon: ^2.16
- yiisoft/yii2: ~2.0.10
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.0
- phpunit/phpunit: ^7.3
This package is auto-updated.
Last update: 2024-09-29 06:03:02 UTC
README
为Yii Framework 2.0收集的有用行为
安装
安装此扩展的首选方法是使用 composer。
运行以下命令之一:
php composer.phar require --prefer-dist indifferend/yii2-behaviors "*"
或者在您的 composer.json
文件的 require 部分添加:
"indifferend/yii2-behaviors": "*"
to the require section of your composer.json
file.
用法
- PurifyBehavior
public function behaviors() { return [ 'purify' => [ 'class' => PurifyBehavior::className(), 'attributes' => ['title', 'content'], 'config' => [ 'AutoFormat.Linkify' => true, 'HTML.TargetBlank' => true, 'HTML.Nofollow' => true ] ] ]; }
- CarbonBehavior
CarbonBehavior 在
afterFind
事件发生时,会自动为 ActiveRecord 对象的一个或多个属性创建一个 Carbon 实例。
public function behaviors() { return [ 'carbon' => [ 'class' => CarbonBehavior::className(), 'attributes' => [ 'createdAt', 'trialEndAt', ] ], ]; } $user = UserModel::findOne(1); var_dump($user->createdAt->year); // 2016 var_dump($user->createdAt->month); // 5 var_dump($user->createdAt->day); // 10 // change date $user->trialEndAt->addYear(); $user->save();
支持我们
您的业务是否依赖于我们的贡献?联系并支持我们在 Patreon。所有的承诺都将专门用于维护和开发新功能。