conquer/select2
Composer 安装命令:
composer require conquer/select2
包简介
Yii2 Select2 widget
关键字:
README 文档
README
Description
Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options. For more information please visit Select2
Installation
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require conquer/select2 "*"
or add
"conquer/select2": "*"
to the require section of your composer.json file.
Usage
Basic usage:
// Form edit view use conquer\select2\Select2Widget; use yii\helpers\ArrayHelper; $form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'items'=>ArrayHelper::map(Catalog::find()->all(), 'id', 'name') ] );
Ajax:
use conquer\select2\Select2Action; ... class SiteController extends Controller { public function actions() { return [ 'ajax' => [ 'class' => Select2Action::className(), 'dataCallback' => [$this, 'dataCallback'], ], ]; } /** * * @param string $q * @return array */ public function dataCallback($q) { $query = new ActiveQuery(Catalog::className()); return [ 'results' => $query->select([ 'catalog_id as id', 'catalog_name as text', ]) ->filterWhere(['like', 'catalog_name', $q]) ->asArray() ->limit(20) ->all(), ]; } } // Form edit view: $form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'ajax' => ['site/ajax'] ] );
Jquery Events:
Array the Select2 JQuery events. You must define events in event-name => event-function format. All events will be stacked in the sequence. Refer the plugin options documentation for details.
For example:
$form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'events' => [ 'select2:open' => "function() { log('open'); }", ] ] );
Initialization of multiple selection in case of using ajax and custom templates.
<?= $form->field($model, 'multipleItems')->widget(Select2Widget::className(), [ 'options' => [ 'placeholder' => 'Select items ...', ], 'ajax' => Url::to(['items/search']), 'multiple' => true, 'items' => ArrayHelper::map($model->multipleItems, 'id', 'text'), // Initial data the same, as returned results from Ajax request items/search 'data' => $model->multipleItems, 'settings' => [ 'ajax' => ['delay' => 250], 'minimumInputLength' => 1, 'minimumResultsForSearch' => -1, /** * Handlebars here is used as example of using template engine * If you will not provide initial data, * custom templates will not access additional info of items */ 'templateResult' => 'js:Handlebars.compile($("#template-result").html())', 'templateSelection' => 'js:Handlebars.compile($("#template-selection").html())', 'escapeMarkup' => 'js:function(markup){ return markup; }', ], ]) ?>
License
conquer/select2 is released under the MIT License. See the bundled LICENSE for details.
conquer/select2 适用场景与选型建议
conquer/select2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81.75k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「widget」 「select2」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 conquer/select2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 conquer/select2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 conquer/select2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony form types to extend built-in types. Ideal for Select2 AJAX implementations.
A custom URL rule class for Yii 2 which allows to create translated URL rules
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 81.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 11
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-07