PHPackages                             marqu3s/yii2-behaviors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marqu3s/yii2-behaviors

ActiveYii2-behavior[Utility &amp; Helpers](/categories/utility)

marqu3s/yii2-behaviors
======================

Collection of Yii2 behaviors

v0.3.7(10y ago)1211.6k↓46.4%4MITPHP

Since Jan 18Pushed 1y ago5 watchersCompare

[ Source](https://github.com/marqu3s/yii2-behaviors)[ Packagist](https://packagist.org/packages/marqu3s/yii2-behaviors)[ Docs](https://github.com/marqu3s/yii2-behaviors)[ RSS](/packages/marqu3s-yii2-behaviors/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (12)Used By (0)

Yii2 Behaviors
==============

[](#yii2-behaviors)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://composer.org). Either run:

```
php composer.phar require --prefer-dist marqu3s/yii2-behaviors "*"

```

or add

```
"marqu3s/yii2-behaviors": "*"

```

to the require section of your composer.json file.

Available Behaviors
-------------------

[](#available-behaviors)

### GRID

[](#grid)

#### SaveGridPaginationBehavior

[](#savegridpaginationbehavior)

Saves the grid's current page and pageSize in PHP Session so you can restore it later automatically when revisiting the page where the grid is.

Usage: On the model that will be used to generate the dataProvider that will populate the grid, attach this behavior.

```
public function behaviors()
{
  return [
    'saveGridPage' => [
      'class' => SaveGridPaginationBehavior::class,
      'sessionVarName' => self::class . 'GridPage',
      'sessionPageSizeName' => self::class . 'GridPageSize'
    ]
  ];
}
```

Then, on your search() method, set the grid current page using one of these:

```
$dataProvider = new ActiveDataProvider(
  [
    'query' => $query,
    'sort' => ...,
    'pagination' => [
      'page' => $this->getGridPage(), //  $this->getGridPageSize(),
      ...
    ]
  ]
);
```

OR

```
$dataProvider->pagination->page = $this->getGridPage();
```

#### SaveGridFiltersBehavior

[](#savegridfiltersbehavior)

Saves the Grid's current filters in PHP Session on every request and use \[\[loadWithFilters()\]\] to get the current filters and assign it to the grid.

Usage: On the model that will be used to generate the dataProvider that will populate the grid, attach this behavior.

```
public function behaviors()
{
  return [
    'saveGridFilters' => [
      'class' => SaveGridFiltersBehavior::class,
      'sessionVarName' => self::class . 'GridFilters'
    ]
  ];
}
```

Then, on your search() method, replace $this-&gt;load() by $dataProvider = $this-&gt;loadWithFilters($params, $dataProvider):

```
$dataProvider = new ActiveDataProvider(
  [
    'query' => $query,
    'sort' => ...,
    'pagination' => [
      'page' => $this->getGridPage(), //  $this->getGridPageSize(),
      ...
    ]
  ]
);

//$this->load($params); // loadWithFilters($params, $dataProvider); // From SaveGridFiltersBehavior
```

#### SaveGridOrderBehavior

[](#savegridorderbehavior)

Saves the Grid's current order criteria in PHP Session.

Usage: On the model that will be used to generate the dataProvider that will populate the grid, attach this behavior.

```
public function behaviors()
{
    return [
        'saveGridOrder' => [
            'class' => SaveGridOrderBehavior::class,
            'sessionVarName' => self::class . 'GridOrder'
        ]
    ];
}
```

Then, on yout search() method, set the grid current order using these code:

```
$dataProvider->sort->attributeOrders = $this->getGridOrder();
```

### ActiveRecord

[](#activerecord)

#### LogChangesBehavior

[](#logchangesbehavior)

Creates a log everytime a model is created or updated. The log entry contains all changed attributes, their old and new values.

Install: Create the necessary table by using the log\_active\_record.sql script or by copying the migration script to your migration directory and execute `yii migrate`. If you want to use your own table, with your own naming conventions, you can customize the behaviour with your table name and columns.

Usage: add it to the behaviors() method of your ActiveRecord model and customize it using it´s attributes.

OPTIONAL: You may implement LogChangesInterface in your ActiveRecord and create a custom `getDeletedRecordText()` that returns a custom log message when a record is deleted.

```
public function behaviors()
{
     return [
         'LogChanges' => [
             'class' => LogChangesBehavior::class,

             // Customization
             'valuesReplacement' => [
                 'active' => [
                     0 => 'No',
                     1 => 'Yes',
                 ]
             ],
             'currencyAttributes' => [
                 'subtotal', 'total', 'tax'
             ]
         ],
     ];
}
```

That's all!

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

11

Last Release

3774d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a79c68a3e0b34ad46bf9a68c697b635521d0483b727b02c28f4d6a7e38337e55?d=identicon)[marqu3s](/maintainers/marqu3s)

---

Top Contributors

[![marqu3s](https://avatars.githubusercontent.com/u/2284983?v=4)](https://github.com/marqu3s "marqu3s (42 commits)")[![ghpeppe](https://avatars.githubusercontent.com/u/14030905?v=4)](https://github.com/ghpeppe "ghpeppe (1 commits)")

---

Tags

yii2Behavior

### Embed Badge

![Health badge](/badges/marqu3s-yii2-behaviors/health.svg)

```
[![Health](https://phpackages.com/badges/marqu3s-yii2-behaviors/health.svg)](https://phpackages.com/packages/marqu3s-yii2-behaviors)
```

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

3030.6k](/packages/sjaakp-yii2-taggable)[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1830.9k](/packages/mdmsoft-yii2-autonumber)[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1174.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)[asinfotrack/yii2-audittrail

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

1727.0k](/packages/asinfotrack-yii2-audittrail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
