https://github.com/yiisoft/yii2-collection
Collection extension for Yii 2
https://github.com/yiisoft/yii2-collection
collection yii2 yii2-extension
Last synced: about 2 months ago
JSON representation
Collection extension for Yii 2
- Host: GitHub
- URL: https://github.com/yiisoft/yii2-collection
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2017-06-06T09:53:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-31T08:51:57.000Z (over 1 year ago)
- Last Synced: 2025-04-10T21:27:26.004Z (about 2 months ago)
- Topics: collection, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 65.4 KB
- Stars: 67
- Watchers: 26
- Forks: 18
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
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).
[](https://packagist.org/packages/yiisoft/yii2-collection)
[](https://packagist.org/packages/yiisoft/yii2-collection)
[](https://travis-ci.org/yiisoft/yii2-collection)Installation
------------The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist yiisoft/yii2-collection
```or add
```json
"yiisoft/yii2-collection": "~1.0.0"
```to the require section of your composer.json.
Configuration
-------------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:```php
/**
* {@inheritdoc}
* @return \yii\db\ActiveQuery|\yii\collection\CollectionBehavior
*/
public static function find()
{
$query = parent::find();
$query->attachBehavior('collection', \yii\collection\CollectionBehavior::class);
return $query;
}
```