yii2 drop-down box comes with search

不言
Release: 2023-03-24 22:44:01
Original
1479 people have browsed it

The content introduced in this article is about the built-in search of the yii2 drop-down box, which has a certain reference value. Now I share it with you. Friends in need can refer to it.

First make sure whether composer is installed. Composer is for It is an indispensable part for PHP programmers. Then hold down the shift key and right-click the mouse in the project directory and click "Open command window here"; the execution of

composer require kartik-v/yii2-widget-select2 "@dev"。
Copy after login

takes a bit long, please wait patiently.

After installation, if it is an AF page

use kartik\select2\Select2; 
 <?= $form->field($model, &#39;charger_id&#39;)->widget(Select2::classname(), [  
                                            &#39;data&#39; => \yii\helpers\ArrayHelper::map(\common\models\Category::find()->asArray()->all(),&#39;id&#39;,&#39;name&#39;),
                                            &#39;options&#39; => [&#39;placeholder&#39; => &#39;请选择 ...&#39;], 
                                        ]); 
 ?>
Copy after login

If it is another page

use kartik\select2\Select2; 
echo Select2::widget([ &#39;name&#39; => &#39;title&#39;, 
    &#39;data&#39; => \yii\helpers\ArrayHelper::map(\common\models\Category::find()->asArray()->all(),&#39;id&#39;,&#39;name&#39;), 
    &#39;options&#39; => [&#39;placeholder&#39; => &#39;请选择...&#39;] 
]);
Copy after login

Of course, the data is requested when the page is loaded model layer; data can also be loaded asynchronously. Try it yourself!

Related recommendations:

yii2 resetful authorization verification


The above is the detailed content of yii2 drop-down box comes with search. 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!