yii2mod/yii2-behaviors

Collection of useful behaviors for Yii Framework 2.0

Maintainers

👁 disem

Package info

github.com/yii2mod/yii2-behaviors

Type:yii2-extension

pkg:composer/yii2mod/yii2-behaviors

Statistics

Installs: 109 352

Dependents: 10

Suggesters: 0

Stars: 31

Open Issues: 3

2.0 2019-06-13 12:34 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 2d35266588f22930d9f87809137536aff510e01a

  • Dmitry Semenov <disemx.woop@gmail.com>
  • Igor Chepurnoy <chepurnoi.igor.woop@gmail.com>

yii2yii2 behaviors

This package is auto-updated.

Last update: 2026-05-29 00:48:06 UTC


README

Collection of useful behaviors for Yii Framework 2.0

👁 Latest Stable Version
👁 Total Downloads
👁 License
👁 Build Status

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

  1. PurifyBehavior
 public function behaviors()
 {
 return [
 'purify' => [
 'class' => PurifyBehavior::className(),
 'attributes' => ['title', 'content'],
 'config' => [
 'AutoFormat.Linkify' => true,
 'HTML.TargetBlank' => true,
 'HTML.Nofollow' => true
 ]
 ]
 ];
 }
  1. 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();

Carbon Documentation

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.