Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yii2mod/yii2-behaviors
Collection of useful behaviors for Yii Framework 2.0
https://github.com/yii2mod/yii2-behaviors
yii2 yii2-behaviors yii2-carbon-behavior yii2-extension yii2-purify-behavior
Last synced: about 1 month ago
JSON representation
Collection of useful behaviors for Yii Framework 2.0
- Host: GitHub
- URL: https://github.com/yii2mod/yii2-behaviors
- Owner: yii2mod
- License: mit
- Created: 2014-11-26T17:17:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-02T17:40:38.000Z (about 5 years ago)
- Last Synced: 2024-09-30T23:50:35.587Z (about 2 months ago)
- Topics: yii2, yii2-behaviors, yii2-carbon-behavior, yii2-extension, yii2-purify-behavior
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 29
- Watchers: 6
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-yii2 - yii2mod/yii2-behaviors
README
Yii2 behaviors
===============================================Collection of useful behaviors for Yii Framework 2.0
[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-behaviors/v/stable)](https://packagist.org/packages/yii2mod/yii2-behaviors) [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-behaviors/downloads)](https://packagist.org/packages/yii2mod/yii2-behaviors) [![License](https://poser.pugx.org/yii2mod/yii2-behaviors/license)](https://packagist.org/packages/yii2mod/yii2-behaviors)
[![Build Status](https://travis-ci.org/yii2mod/yii2-behaviors.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-behaviors)Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
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**
```php
public function behaviors()
{
return [
'purify' => [
'class' => PurifyBehavior::className(),
'attributes' => ['title', 'content'],
'config' => [
'AutoFormat.Linkify' => true,
'HTML.TargetBlank' => true,
'HTML.Nofollow' => true
]
]
];
}
```2) **CarbonBehavior**
> CarbonBehavior automatically creates a Carbon Instance for one or multiple attributes of an ActiveRecord
object when `afterFind` event happen.```php
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](http://carbon.nesbot.com/docs/#api-introduction)
## Support us
Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod).
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.