sjaakp / yii2-random-provider
Random ActiveDataProvider for Yii 2.0 GridView or ListView
Installs: 122
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-10-28 15:31:49 UTC
README
ActiveDataProvider with random selection
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.