Download the PHP package yii2tech/ar-search without Composer

On this page you can find all versions of the php package yii2tech/ar-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ar-search

ActiveRecord Search Model Extension for Yii2


This extension provides unified search model for Yii ActiveRecord.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Usage

This extension provides unified search model for Yii ActiveRecord via special model class - \yii2tech\ar\search\ActiveSearchModel.

This model is able to fetch its attributes, validation rules and filtering logic from the 'slave' source ActiveRecord model specified via \yii2tech\ar\search\ActiveSearchModel::$model. Thus you do not need to declare a separated model class for searching and define a filter logic. For example:

ActiveSearchModel picks all 'safe' attributes of the 'slave' model and use them as own attributes. Thus you can use any attribute, which is marked as 'safe' in related ActiveRecord model in the scope of this class. For example:

Inherited attributes may be used while composing web forms, which should collect filter data. For example:

Attribute labels and hints are also inherited from the 'slave' model.

The main method of \yii2tech\ar\search\ActiveSearchModel is search(). It loads filter attributes from given data array, validates them an creates a \yii\data\ActiveDataProvider instance applying own attributes as a query filter condition.

ActiveSearchModel uses a sophisticated logic for the query filtering, based on the attribute types, specified by \yii2tech\ar\search\ActiveSearchModel::$searchAttributeTypes, which value is extracted from \yii2tech\ar\search\ActiveSearchModel::$model by default and filter operators list, specified via \yii2tech\ar\search\ActiveSearchModel::$filterOperators. By default \yii\db\QueryInterface::andFilterWhere() will be used for the filter composition. For the 'string' attributes it will be used with 'like' operator. For 'integer' and 'float' ('double') method andFilterCompare() will be used, if it is available.

Heads up! Do not abuse ActiveSearchModel usage. It has been designed to cover only the simplest cases, when search logic is trivial. You should always create a separated search model in case, it requires complex logic of composition of the search query.

Adjusting Data Provider

You may want to change some settings of the data provider, created by the search() method: change pagination or sort settings and so on. You can do this via \yii2tech\ar\search\ActiveSearchModel::$dataProvider. For example:

Adjusting Search Query

You may use \yii2tech\ar\search\ActiveSearchModel::EVENT_AFTER_CREATE_QUERY event to adjust the search query instance adding relation eager loading or permanent conditions. For example:

You may also specify query object directly via \yii2tech\ar\search\ActiveSearchModel::$dataProvider. For example:

Filter Operators

You can control the operators to be used for the query filtering via \yii2tech\ar\search\ActiveSearchModel::$filterOperators. It defines a mapping between the attribute type and the operator to be used with \yii\db\QueryInterface::andFilterWhere(). Each value can be a scalar operator name or a PHP callback, accepting query instance, attribute name and value. For example:

ActiveSearchModel allows filtering for the attributes using andFilterCompare() method of the query (for example: \yii\db\Query::andFilterCompare()), which allows specifying filter value in format: {operator}{value} (for example: >10, <=100 and so on). The list of attribute names, for which usage of such comparison is allowed is controlled by \yii2tech\ar\search\ActiveSearchModel::$compareAllowedAttributes. For example:

You can set compareAllowedAttributes to *, which indicates any float or integer attribute will be allowed for comparison.

Note: \yii2tech\ar\search\ActiveSearchModel::$filterOperators take precedence over \yii2tech\ar\search\ActiveSearchModel::$compareAllowedAttributes.

Working Without 'Slave' Model

Although in most cases setup of \yii2tech\ar\search\ActiveSearchModel::$model is a quickest way to configure ActiveSearchModel instance, it is not mandatory. You can avoid setup of the 'slave' model and configure all search related properties directly. For example:


All versions of ar-search with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yii2tech/ar-search contains the following files

Loading the files please wait ....