sdev/sd-plugin
Composer 安装命令:
composer require sdev/sd-plugin
包简介
Yii2 ActiveForm extension
README 文档
README
为 Yii2 ActiveForm 添加 hint 提示和智能 placeholder 功能。
安装
composer require sdev/sd-plugin 基本使用 php use sdplugin\ActiveForm; 使用示例 class User extends \yii\db\ActiveRecord { public function attributeLabels() { return [ 'username' => '用户名', 'email' => '电子邮箱', 'phone' => '手机号码', ]; } public function attributeHints() { return [ 'username' => '用户名长度为3-20个字符,只能包含字母、数字和下划线', 'email' => '请填写有效的邮箱地址,用于接收验证邮件', 'phone' => '请输入有效的手机号码,用于紧急联系', ]; } } use sdplugin\ActiveForm; $form = ActiveForm::begin(); // 1. 使用 attributeHints 中的提示 echo $form->field($model, 'username') ->textInput() ->hint() // 自动获取:用户名长度为3-20个字符... ->placeholder(); // 2. 使用 attributeLabels 生成提示 echo $form->field($model, 'birth_date') ->textInput() ->hint() // 自动生成:出生日期的说明 ->placeholder(); // 3. 使用字段名生成提示 echo $form->field($model, 'home_address') ->textInput() ->hint() // 自动生成:Home Address字段的说明 ->placeholder(); // 4. 自定义提示(覆盖自动生成) echo $form->field($model, 'email') ->textInput() ->hint('请填写真实邮箱') // 自定义提示 ->placeholder(); ActiveForm::end(); use sdplugin\ActiveForm; $form = ActiveForm::begin(); // 现在默认就是 input-before 和 inline 模式 echo $form->field($model, 'username') ->textInput() ->hint('用户名提示') // 默认显示在输入框前,单行模式 ->placeholder(); // 自动生成 // 可以覆盖默认值 echo $form->field($model, 'email') ->textInput() ->hint('邮箱提示') ->hintMode('icon') // 覆盖为图标模式 ->hintPosition('label-after'); // 覆盖为标签后 // 另一个例子 echo $form->field($model, 'phone') ->textInput() ->hint('手机号提示'); // 使用默认的 input-before 和 inline ActiveForm::end(); php use sdplugin\ActiveForm; $form = ActiveForm::begin(); // 测试 label-after echo $form->field($model, 'username') ->textInput() ->hint('用户名提示') ->hintPosition('label-after'); // 现在应该正常工作了 // 测试 placeholder 优先级 echo $form->field($model, 'email', [ 'inputOptions' => [ 'placeholder' => '这个会被覆盖' ] ]) ->textInput() ->placeholder('这个会生效'); // 现在优先级最高 ActiveForm::end(); php use sdplugin\ActiveForm; $form = ActiveForm::begin(); // 默认就是 label-after 和 icon 模式 echo $form->field($model, 'username') ->textInput() ->hint('用户名提示') ->placeholder(); // 自动生成 // 测试 placeholder 优先级 echo $form->field($model, 'email') ->textInput(['placeholder' => '这个会被覆盖']) ->placeholder('这个会生效'); // 现在这个优先级最高 // 其他输入类型 echo $form->field($model, 'password') ->passwordInput(['placeholder' => '会被覆盖']) ->placeholder('密码 placeholder'); echo $form->field($model, 'description') ->textarea(['placeholder' => '会被覆盖']) ->placeholder('描述 placeholder'); ActiveForm::end(); $form = ActiveForm::begin(); // 标签后图标提示 echo $form->field($model, 'username') ->textInput() ->hint('用户名提示') ->hintPosition('label-after'); // 输入框前单行提示 echo $form->field($model, 'email') ->textInput() ->hint('邮箱提示') ->hintMode('inline') ->hintPosition('input-before'); // 输入框后图标提示(默认) echo $form->field($model, 'phone') ->textInput() ->hint('手机号提示'); ActiveForm::end(); 提示位置 标签后 (label-after) php ->hintPosition('label-after') 提示显示在标签文字后面 输入框前 (input-before) php ->hintPosition('input-before') 提示显示在输入框前面 输入框后 (input-after) - 默认 php ->hintPosition('input-after') 提示显示在输入框后面 提示模式 图标模式(默认) 鼠标悬停显示提示 php ->hint('提示内容') ->hintMode('icon') 单行模式 直接显示提示文字 php ->hint('提示内容') ->hintMode('inline') 图标控制 php // 显示图标(默认) ->showIcon(true) // 不显示图标 ->showIcon(false) 智能 Placeholder php // 自动生成 ->placeholder() // 自定义 ->placeholder('自定义提示') 手动加载资源(可选) 如果需要手动控制资源加载: php use sdplugin\assets\SdPluginAsset; // 手动注册资源 SdPluginAsset::register($this); 完整示例 php echo $form->field($model, 'username') ->textInput() ->placeholder() ->hint('3-20个字符') ->hintPosition('label-after'); echo $form->field($model, 'password') ->passwordInput() ->hint('至少8位字符') ->hintMode('inline') ->hintPosition('input-before') ->showIcon(false); echo $form->field($model, 'email') ->textInput() ->hint('用于接收验证邮件') ->hintPosition('input-after'); echo $form->field($model, 'bio') ->textarea() ->hint('简单自我介绍') ->hintMode('inline') ->hintPosition('label-after');
sdev/sd-plugin 适用场景与选型建议
sdev/sd-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bootstrap」 「hint」 「placeholder」 「yii2」 「activeform」 「ChinaBUG」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sdev/sd-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sdev/sd-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sdev/sd-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A code hint file for the solr 2.4 extension.
A simple way to create typed collections in PHP - build on Illuminate\Support\Collection
A simple way to create typed collections in PHP - build on Illuminate\Support\Collection
A plugin which generates an invisible SVG of specific dimensions for use when lazyloading images in Craft CMS templates.
The InstantConfigurationCopy module provides easy way to copy configuration field information for admin in back office Magento 2.
A code hint file for the UOPZ extension
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-20