Yii2 drop-down box with search function, yii2 drop-down box search function _php Tutorial

Source: Internet
Author: User

Yii2 drop-down box with search function, yii2 drop-down box search function


Simple small function, but it's pretty cool to use. Share to let more people have faster development efficiency, happy heart happy programming.
Author: White Wolf Source: http://www.manks.top/yii2_dropdown_search.html This article copyright belongs to the author, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location gives the original text connection, Otherwise, the right to pursue legal liability is retained.

If you have not used composer, you can out, see my tutorial to share, composer is absolutely necessary magic has wood. Speaking of this point, we hurriedly use composer to install it.

No hurry, first to see what kind of, otherwise are not in the mood without desire to look down. The original text comes with a picture, can refer to.

What, not interested? Continue to see, after watching the operation side can feel good where.
There is Wood has a feeling very handsome, of course, far more than, but also very on the grade with the effect is also a lever of wood has.
All right, hurry up and install, or you'll have a long chat.

composer require kartik-v/yii2-widget-select2 "@dev"#特别说明,因为这里安装的dev版本,也就是开发版本,不稳定版本,如果你的项目是git托管的,composer安装下来之后这里记得删掉 \vendor\kartik-v\yii2-widget-select2目录下的.git文件,不然你提交不上去的哦

Just wait for him for about 5 minutes, it's ready to install, and then we can start using it like this one.
If your form is activeform, please use

use kartik\select2\Select2; //$data是键值对数组哦,key-value ,下面所声明的所有$data均为键值对数组,以该数组为例 $data = [2 => 'widget', 3 => 'dropDownList', 4 => 'yii2']; echo $form->field($model, 'title')->widget(Select2::classname(), [ 'data' => $data, 'options' => ['placeholder' => '请选择 ...'], ]);

If your form is non-activeform, you can refer to the following

use kartik\select2\Select2; echo Select2::widget([ 'name' => 'title', 'data' => $data, 'options' => ['placeholder' => '请选择...'] ]);

Non-ACTIVEFOMR generated update data will need to be selected by default, OK, add value can be

use kartik\select2\Select2; echo Select2::widget([ 'name' => 'title', 'value' => 2, 'data' => $data, 'options' => ['placeholder' => '请选择...'] ]);#但是如果你的表单是ActiveForm生成的,但是往往字段不是表字段怎么办呢?更好办啦,以上面的为例,你只需要指定$model->title = ['title1', 'title2'];即可

Continue Reading

http://www.bkjia.com/PHPjc/1125683.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125683.html techarticle Yii2 drop-down box with search function, yii2 drop-down box search function simple small function, but it is quite cool to use. Share it so that more people have faster development efficiency, happy heart happy ...

  • Related Article

    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.