[extension] sjaakp/yii2-random-provider


yii2-random-provider

  1. Installation
  2. Using RandomProvider

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.