PHPackages                             laxity7/yii2-collection - 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. laxity7/yii2-collection

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

laxity7/yii2-collection
=======================

Active Record Collection implementation for the Yii framework

1.0.0(7y ago)01.2k↑14.3%BSD-3-ClausePHPPHP &gt;=7.1

Since Apr 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/laxity7/yii2-collection)[ Packagist](https://packagist.org/packages/laxity7/yii2-collection)[ RSS](/packages/laxity7-yii2-collection/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

ActiveRecord Collection Extension for Yii 2
===========================================

[](#activerecord-collection-extension-for-yii-2)

This extension provides a generic data collection as well as a collection for the ActiveRecord DB layer of Yii 2.

**Development is currently in experimental state. It is not ready for production use and may change significantly.**

For license information check the [LICENSE](LICENSE.md)-file.

Documentation is at [docs/guide/README.md](docs/guide/README.md).

[![License](https://camo.githubusercontent.com/b2bf99b6e9a3c15b62e7be870f3e6c3f78423fd2e99e9d3bd6cb288115f076b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6178697479372f796969322d636f6c6c656374696f6e2e737667)](https://github.com/laxity7/yii2-collection/blob/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/1e494dbe03384aa222a49c8229f0511860e11975210775aac8eac598b4ac9941/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6178697479372f796969322d636f6c6c656374696f6e2e737667)](https://packagist.org/packages/laxity7/yii2-collection)[![Total Downloads](https://camo.githubusercontent.com/7a8f43b7f212ac87c89a2f250b70bf1381fe9c9ff43877f8b6893b85f7f22104/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6178697479372f796969322d636f6c6c656374696f6e2e737667)](https://packagist.org/packages/laxity7/yii2-collection)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist laxity7/yii2-collection

```

or add

```
"laxity7/yii2-collection": "~1.0.0"
```

to the require section of your composer.json.

\##Basic usage

Collection is a container for a set of items.

It provides methods for transforming and filtering the items as well as sorting methods, which can be applied using a chained interface. All these operations will return a new collection containing the modified data keeping the original collection as it was as long as containing objects state is not changed.

```
$collection = new Collection([1, 2, 3]);
echo $collection->map(function($i) { // [2, 3, 4]
    return $i + 1;
})->filter(function($i) { // [2, 3]
    return $i < 4;
})->sum(); // 5
```

The collection implements \[\[ArrayAccess\]\], \[\[Iterator\]\], and \[\[Countable\]\], so you can access it in the same way you use a PHP array. A collection however is read-only, you can not manipulate single items.

```
$collection = new Collection([1, 2, 3]);
echo $collection[1]; // 2
foreach($collection as $item) {
    echo $item . ' ';
} // will print 1 2 3
```

Configuration for ActiveRecord
------------------------------

[](#configuration-for-activerecord)

To use this extension, you have to attach the `yii\collection\CollectionBehavior` to the `ActiveQuery` instance of your `ActiveRecord` classes by overriding the `find()` method:

```
/**
 * {@inheritdoc}
 * @return \yii\db\ActiveQuery|\yii\collection\CollectionBehavior
 */
public static function find()
{
    $query = parent::find();
    $query->attachBehavior('collection', \yii\collection\CollectionBehavior::class);
    return $query;
}
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

2635d ago

### Community

Maintainers

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

---

Top Contributors

[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (9 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (7 commits)")[![laxity7](https://avatars.githubusercontent.com/u/6792144?v=4)](https://github.com/laxity7 "laxity7 (3 commits)")[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (2 commits)")[![softark](https://avatars.githubusercontent.com/u/342857?v=4)](https://github.com/softark "softark (2 commits)")[![vanodevium](https://avatars.githubusercontent.com/u/16780069?v=4)](https://github.com/vanodevium "vanodevium (1 commits)")[![KartaviK](https://avatars.githubusercontent.com/u/5941637?v=4)](https://github.com/KartaviK "KartaviK (1 commits)")[![machour](https://avatars.githubusercontent.com/u/304450?v=4)](https://github.com/machour "machour (1 commits)")

---

Tags

collectionyii2active-record

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laxity7-yii2-collection/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[yii2mod/collection

Basic collection library

31183.9k5](/packages/yii2mod-collection)[hiqdev/yii2-collection

Collection library for Yii2

1045.6k6](/packages/hiqdev-yii2-collection)[v0lume/yii2-meta-tags

DB based model meta data for SEO

204.1k](/packages/v0lume-yii2-meta-tags)

PHPackages © 2026

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