PHPackages                             pozitronik/yii2-searchwidget - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. pozitronik/yii2-searchwidget

ActiveLibrary[Search &amp; Filtering](/categories/search)

pozitronik/yii2-searchwidget
============================

Quick search widget

0.8.1(3y ago)013LGPL-3.0-or-laterPHPPHP &gt;=8.0

Since Nov 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/pozitronik/yii2-searchwidget)[ Packagist](https://packagist.org/packages/pozitronik/yii2-searchwidget)[ RSS](/packages/pozitronik-yii2-searchwidget/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (3)Used By (0)

yii2-searchwidget
=================

[](#yii2-searchwidget)

Quicksearch widget implementation

Installation
============

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Run

```
php composer.phar require pozitronik/yii2-searchwidget "dev-master"

```

or add

```
"pozitronik/yii2-searchwidget": "dev-master"

```

to the require section of your `composer.json` file.

Requirements
============

[](#requirements)

Yii2, PHP &gt;= 8.0

Configuration
=============

[](#configuration)

There are two ways for widget configuration. Preferred way is to configure it as a component, like:

```
...
'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Users' => [
                'class' => Users::class
            ],
            ...
        ],
        ...
    ],
    ...
```

Alternatively, you can pass configuration to widget itself:

```
    SearchWidget::widget([
        'models' => [
            'Users' => [
                'class' => Users::class
            ],
            ...
        ]
]);
```

Configuration parameters
------------------------

[](#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:

```
'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Model1Alias' => [
                'class' => Model1::class
            ],
            'Model2Alias' => [
                'class' => Model2::class
            ],
            ...
        ]
    ]
    ...
]
```

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:

```
...
'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'ajaxEndpoint' => '/site/search',
        'models' => [
            'Users' => [
                'class' => Users::class,
                'template' => '{{name}}{{controller}}Edit',
                'header' => 'Users',
                'limit' => 3,
                'attributes' => [
                    'username',
                    ['email', SearchWidget::SEARCH_TYPE_LIKE_BEGINNING]
                ]
            ],
            'Products' => [
                'class' => Products::class,
                'ajaxEndpoint' => '/products/search',
                'templateView' => '@app/views/products/search-template'
                'header' => 'Products',
                'limit' => null,
                'attributes' => [
                    'name',
                     ['code', SearchWidget::SEARCH_TYPE_EQUAL]
                ]
            ]
        ],
        ...
    ],
    ...
```

Adding alternative configuration
--------------------------------

[](#adding-alternative-configuration)

If you want to create widgets, which implementing different searches, you can configure them as separate components:

```
...
'components' => [
    'usersSearchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Users' => [
                'class' => Users::class,
            ]
        ],
    ],
    'productsSearchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Products' => [
                'class' => Products::class,
            ]
        ],
    ],
```

Then you need to pass component name to each widget:

```
    SearchWidget::widget(['componentName' => 'usersSearchWidget']);//search only in users
    SearchWidget::widget(['componentName' => 'productsSearchWidget']);//search only in products
```

Alternatively, you can pass configuration to widget itself, as described in \[Configuration\] section.

Search method
=============

[](#search-method)

todo

Search result templates
=======================

[](#search-result-templates)

todo

License
=======

[](#license)

GNU GPL v3.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

1325d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2357892?v=4)[Pavel Dubrovsky](/maintainers/pozitronik)[@pozitronik](https://github.com/pozitronik)

---

Top Contributors

[![pozitronik](https://avatars.githubusercontent.com/u/2357892?v=4)](https://github.com/pozitronik "pozitronik (57 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/pozitronik-yii2-searchwidget/health.svg)

```
[![Health](https://phpackages.com/badges/pozitronik-yii2-searchwidget/health.svg)](https://phpackages.com/packages/pozitronik-yii2-searchwidget)
```

###  Alternatives

[awesome-nova/dependent-filter

Dependent filters for Laravel Nova

26193.1k](/packages/awesome-nova-dependent-filter)[algolia/php-dom-parser

A simple tool to turn DOM into Algolia search friendly record objects.

181.8k](/packages/algolia-php-dom-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
