yii2mod / yii2-behaviors
Collection of useful behaviors for Yii Framework 2.0
Installs: 95 565
Dependents: 10
Suggesters: 0
Security: 0
Stars: 29
Watchers: 6
Forks: 4
Open Issues: 3
Type:yii2-extension
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-11-29 05:14:51 UTC
README
Collection of useful behaviors for Yii Framework 2.0
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii2mod/yii2-behaviors "*"
or add
"yii2mod/yii2-behaviors": "*"
to the require section of your composer.json
file.
Usage
- PurifyBehavior
public function behaviors() { return [ 'purify' => [ 'class' => PurifyBehavior::className(), 'attributes' => ['title', 'content'], 'config' => [ 'AutoFormat.Linkify' => true, 'HTML.TargetBlank' => true, 'HTML.Nofollow' => true ] ] ]; }
- CarbonBehavior
CarbonBehavior automatically creates a Carbon Instance for one or multiple attributes of an ActiveRecord object when
afterFind
event happen.
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();
Support us
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.