pahanini/yii2-refiner 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pahanini/yii2-refiner

Composer 安装命令:

composer require pahanini/yii2-refiner

包简介

Helps to add additional where params to active query (refine query)

README 文档

README

Helps to add additional 'where' conditions based on http request to active queries (refine search queries) and also automates calculation of possible values of different filters used to build UI. Can be used in RESTful APIs.

Terms

"Base query" - ActiveQuery (e.g. MySqlQuery, SphinxQuery) to find all possible items before any refiner will be applied. E.g. SELECT * FROM products WHERE balance > 0

"Refiner" is object which:

  • calculates all possible (or independent) values for UI, e.g. list of possible product's categories, maximum and minimum price between products (all callback).
  • analyzes http request and add additional where conditions to basic query (refine callback)
  • calculates active values of UI. Active values depends on values of other refiners (active callback).

"Refiner Set" - object which contain one or more refiners and base query. Refiner set applies all refiners to query.

Installation

Add

"pahanini/yii2-refiner": "*"

to the require section of your composer.json file.

Usage

Set

Refiner set has two main independent functions:

  • getRefinedQuery - returns query modified by refiners
  • getRefinerValues - returns all refiners values

Refiner

Each refiner modifies base query according to http query params. To modify query refiner calls refine($query, $params) callback function. This function must return modified query. Function example:

$this->refine = function($query, $params) {
    return $query->andWhere('has_discount > :val', [':val' => $params]);
}

Note:

  • if http param does no exist refine function will not be called
  • if $paramSeparator property is set and http param is not an array then http param wll converted to array using $paramSeparator property
  • if $paramToArray property is set and http param is not an array then it will converted to array with one element
  • if $paramType is set then http param type will be changed using php setType function

Some examples:

public function init()
{
	$this->refinerSet = new \pahanini\refiner\Set([
		'refiners' => [
			// standard range
			'price' => [
				'class' => '\pahanini\refiner\db\Range',
			],
			'category' => [
				'class' => '\pahanini\refiner\db\Count',
			],
			// Select color values from another model
			'onlyRedColor' => [
			    'refine' => function($query, $param) {
			        return $query->andWhere('color = "red"');
			    },
			    'all' => function($query) {
			        return $query->select('COUNT(*)')->andWhere('color = "red"')
			    }
			]
		]
	])
}


public function actionSearch()
{
	$query = Product::find()->andWhere('balance > 0');
	$refinerResult = $this->refinerSet->applyTo($query);
	$this->render('search', ['query' => $query, 'refiners' => $this->refinerSet->getRefinerValues()])
}

统计信息

  • 总下载量: 671
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-05-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固