PHPackages                             sdev/sd-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. sdev/sd-plugin

ActiveYii2-extension[Templating &amp; Views](/categories/templating)

sdev/sd-plugin
==============

Yii2 ActiveForm extension

00PHP

Since Nov 21Pushed 5mo agoCompare

[ Source](https://github.com/ChinaBUG/sd-plugin)[ Packagist](https://packagist.org/packages/sdev/sd-plugin)[ RSS](/packages/sdev-sd-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SD-Plugin - Yii2 ActiveForm Extension
=====================================

[](#sd-plugin---yii2-activeform-extension)

为 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');
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance47

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1389ab0ca776a64fe06326ce2fd127b4dead984c7216fa155334bdf9dc48bf29?d=identicon)[ChinaBUG](/maintainers/ChinaBUG)

---

Top Contributors

[![ChinaBUG](https://avatars.githubusercontent.com/u/6193759?v=4)](https://github.com/ChinaBUG "ChinaBUG (5 commits)")

### Embed Badge

![Health badge](/badges/sdev-sd-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/sdev-sd-plugin/health.svg)](https://phpackages.com/packages/sdev-sd-plugin)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
