Download the PHP package pozitronik/yii2-searchwidget without Composer
On this page you can find all versions of the php package pozitronik/yii2-searchwidget. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pozitronik/yii2-searchwidget
More information about pozitronik/yii2-searchwidget
Files in pozitronik/yii2-searchwidget
Package yii2-searchwidget
Short Description Quick search widget
License LGPL-3.0-or-later
Informations about the package yii2-searchwidget
yii2-searchwidget
Quicksearch widget implementation
Installation
The preferred way to install this extension is through composer.
Run
or add
to the require section of your composer.json
file.
Requirements
Yii2, PHP >= 8.0
Configuration
There are two ways for widget configuration. Preferred way is to configure it as a component, like:
Alternatively, you can pass configuration to widget itself:
Configuration parameters
- class: the component class, it always must be
SearchWidget::class
. - ajaxEndpoint: the endpoint URL for all searches requests. It must be handled by
SearchAction::class
. Value by default is'/site/search'
. - models: the list of ActiveRecord models, which to search in. Every item key must contain arbitrary but unique model alias, like:
Searches for each model can be configured in there:
- class: (string) the model class name.
- ajaxEndpoint: the endpoint URL for current model searches requests. It overrides similar global option, but not set by default.
- method: (string) if the model implements it own search method, its name can be specified here. See [Search method](#Search method) section for details. By default, model will be threatened as ActiveRecord and standard SQL-searches will be used.
- template: (string) the search result raw template code. Ignored by default. If set, it has higher priority to templateView parameter. See also [Search result templates](#Search result templates) section.
- templateView (string) the path to search result template view. If not set, then default template view will be used.
- header: (string) the header for model search results list.
- limit (null|int) the limit for search results, set null to disable limitations. Default value is 5.
- attributes: (string[]) the list of model attributes names to search in them. Each attribute can be specified in two methods: just by attribute string name, or as array, where the first item is the attribute name, and the second item is attribute search type. Supported search types are:
SearchWidget::SEARCH_TYPE_EQUAL
: attribute value must be equal to search term.SearchWidget::SEARCH_TYPE_LIKE
: attribute value must contain the search term.SearchWidget::SEARCH_TYPE_LIKE_BEGINNING
: attribute value must begins with the search term.SearchWidget::SEARCH_TYPE_LIKE_ENDING
: attribute value must ends to search term.
All search types are case-insensitive.
Next, some configuration example is given:
Adding alternative configuration
If you want to create widgets, which implementing different searches, you can configure them as separate components:
Then you need to pass component name to each widget:
Alternatively, you can pass configuration to widget itself, as described in [Configuration] section.
Search method
todo
Search result templates
todo
License
GNU GPL v3.