Home > PHP Framework > YII > body text

How to use yii2 search box

Release: 2019-12-24 13:43:14
Original
2729 people have browsed it

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"
Copy after login

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

"kartik-v/yii2-widget-select2": "@dev"
Copy after login

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 ...']
]);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!