Home  >  Article  >  PHP Framework  >  How to use yii2 search box

How to use yii2 search box

尚
Original
2019-12-24 13:43:142755browse

How to use yii2 search box

The yii2 search box can be implemented using the select2 component and the select2 jQuery plug-in composed of a Yii2 enhancement package.

The select2 jQuery plug-in consists of select2 components and a Yii2 enhancement package. This input control is a jQuery-based alternative to the select box. It supports searches, remote datasets, and infinite scrolling of results.

This component is designed specifically for bootstrap 3 style and provides some improvements. If the browser does not support jQuery, the component even works with a normal HTML selection or input text. The most commonly used scenario is to automatically enter keywords and match selections when there is too much drop-down content.

The usage effect is as follows:

How to use yii2 search box

##Installation

Composer is the best installation method (recommended). Run the following commands to install and switch Go to the project root directory


composer require kartik-v/yii2-widget-select2 "@dev"

or add the following code to the require location in the composer.json file in the root directory

"kartik-v/yii2-widget-select2": "@dev"

Note: composer has not been updated for a long time, please update composer self-update first

Usage

use kartik\select2\Select2;

// Normal select with ActiveForm & model
echo $form->field($model, 'state_1')->widget(Select2::classname(), [
    'data' => $data,
    'language' => 'de',
    'options' => ['placeholder' => 'Select a state ...'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);

// Multiple select without model
echo Select2::widget([
    'name' => 'state_2',
    'value' => '',
    'data' => $data,
    'options' => ['multiple' => true, 'placeholder' => 'Select states ...']
]);

PHP Chinese website has a large number of free

Yii introductory tutorials, everyone is welcome to learn!

The above is the detailed content of How to use yii2 search box. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to pronounce yii?Next article:How to pronounce yii?