sjaakp/yii2-random-provider

Random ActiveDataProvider for Yii 2.0 GridView or ListView

1.0.1 2019-12-09 15:17 UTC

This package is auto-updated.

Last update: 2022-01-09 20:01:40 UTC


README

ActiveDataProvider with random selection

Latest Stable Version Total Downloads License

RandomProvider is derived from ActiveDataProvider of the Yii 2.0 PHP Framework. It selects the records in a random fashion, which in some cases may be more attractive than the orderly way a regular ActiveDataProvider (usually) does it. RandomProvider is intended to co-operate with my LoadMorePager, but it will work with LinkPager or other pagers as well.

Notice that RandomProvider doesn't support CUBRID or dblib database drivers. Moreover, I only tested it with mysql. I'm pretty sure it'll work with other drivers, though. If you have any experiences to share, I'll appreciate that.

Notice also that RandomProvider makes use of an algorithm named 'Order By Rand()'. This is rather slow, and doesn't scale very well. Therefore, it is advised to use RandomProvider only with relatively small data sets (think of less than a few thousands of records). More information here.

A demonstration of RandomProvider is here.

Installation

Install yii2-random-provider in the usual way with Composer. Add the following to the require section of your composer.json file:

"sjaakp/yii2-random-provider": "*"

or run:

composer require sjaakp/yii2-random-provider

You can manually install yii2-random-provider by downloading the source in ZIP-format.

Using RandomProvider

RandomProvider is a drop-in replacement for Yii's ActiveDataProvider. Just use it like ActiveDataProvider.