Home >Backend Development >PHP Tutorial >yii2 drop-down box comes with search
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"。
takes a bit long, please wait patiently.
After installation, if it is an AF page
use kartik\select2\Select2; <?= $form->field($model, 'charger_id')->widget(Select2::classname(), [ 'data' => \yii\helpers\ArrayHelper::map(\common\models\Category::find()->asArray()->all(),'id','name'), 'options' => ['placeholder' => '请选择 ...'], ]); ?>
If it is another page
use kartik\select2\Select2; echo Select2::widget([ 'name' => 'title', 'data' => \yii\helpers\ArrayHelper::map(\common\models\Category::find()->asArray()->all(),'id','name'), 'options' => ['placeholder' => '请选择...'] ]);
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!