ArrayQuery Component

What is the ArrayQuery Component?

This extension allows you to implement searching/filtering to arrays. Its quite useful when displaying array data in GridViews with ArrayDataProviders.

This extension implements the following conditions:

  • Equal (can also be used for a reverse action not equal)
  • GreaterThan
  • GreaterThanOrEqual
  • LessThan
  • LessThanOrEqual
  • Like
  • NotLike

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "2amigos/yii2-arrayquery-component" "*"

or add the following to the require section of your application's composer.json file:

"2amigos/2amigos/yii2-arrayquery-component" : "*" 

Usage example

The following makes use of the NotLike ("~") and Equal ("=") conditions.

\\ $models is the array elements to used with ArrayDataProvider
$query = new ArrayQuery($models);

$models = $query
    ->addCondition('name', '~2amigos')
    ->addCondition('name', 'Antonio', 'or')
    ->find();

$dataProvider = new ArrayDataProvider([
    'allModels' => $models,
    'pagination' => [
        'pageSize' => 50,
    ],
    'sort' => [
        'attributes' => [], // to be specified
    ],
]);

Share this

Contributors Thanks All

 

Do you have a good idea? Why Don't We Talk?