Yii2 example of a drop-down box with search function, yii2 drop-down box _ PHP Tutorial

Source: Internet
Author: User
Yii2 has a detailed example of the drop-down box with the search function, and yii2 has a drop-down box. Yii2 provides a detailed example of the drop-down box with the search function. the yii2 drop-down box provides simple and small functions, but it is quite easy to use. Share it with others to make development more efficient and happy. yii2 provides detailed examples of the drop-down box with search function, and yii2 drop-down box

Simple and small functions, but it is quite easy to use. Share it to let more people have a faster development efficiency, happy and happy programming.

If you have not used composer, you can get out of it. in my tutorials, composer is absolutely magical. Let's talk about this point. let's use composer for installation.

First, we will show you:

The following describes the implementation methods:

Composer require kartik-v/yii2-widget-select2 "@ dev" # special note, because the dev version installed here, that is, the development version, the unstable version, if your project is hosted by git, after the composer is installed, remember to delete the \ vendor \ kartik-v \ yii2-widget-select2 directory. git file, or you cannot submit it.

It will take about five minutes for him to complete the installation. then we can start using it like below.

// If your form is ActiveForm, use

Use kartik \ select2 \ Select2; // $ data is a key-value pair array. key-value, all $ data declared below are key-value pairs, take this array as an example $ data = [2 => 'widget ', 3 => 'dropdownlist', 4 => 'ii2']; echo $ form-> field ($ model, 'title')-> widget (Select2: classname (), ['data' => $ data, 'options' => ['holder' => 'select... '],]);

// If your form is not ActiveForm, you can refer to the following

Use kartik \ select2 \ Select2; echo Select2: widget (['name' => 'title', 'data' => $ data, 'options' => ['holder' => 'select... ']);

# When updating data generated by non-ActiveFomr, it must be selected by default. add the value.

Use kartik \ select2 \ Select2; echo Select2: widget (['name' => 'title', 'value' => 2, 'data' => $ data, 'options' => ['holder' => 'select... ']);

# What if your form is generated by ActiveForm but the field is often not a table field? For example, you only need to specify $ model-> title = ['title1', 'title2 '];

The above content is a detailed example of the yii2 drop-down box with search function introduced by Xiaobian. I hope to help you and thank you very much for your support for the help House website!

Simple and small functions, but it is quite easy to use. Share it so that more people can develop more efficiently and be happy...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.