PHPackages                             hbhe/yii2-toggle-column - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hbhe/yii2-toggle-column

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

hbhe/yii2-toggle-column
=======================

Provides a toggle data column and action

2361PHP

Since Sep 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/hbhe/yii2-toggle-column)[ Packagist](https://packagist.org/packages/hbhe/yii2-toggle-column)[ RSS](/packages/hbhe-yii2-toggle-column/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Toggle data column for Yii2
===========================

[](#toggle-data-column-for-yii2)

Provides a toggle data column and action

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist hbhe/yii2-toggle-column "*"

```

or add

```
"hbhe/yii2-toggle-column": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

```
// Controller文件中
use hbhe\grid\actions\ToggleAction;

public function actions()
{
    return [
        'toggle-status' => [
            'class' => ToggleAction::className(),
            'onValue' => User::STATUS_ACTIVE,
            'offValue' => User::STATUS_NOT_ACTIVE,
            'modelClass' => 'common\models\User',
            'attribute' => 'status',
            // Uncomment to enable flash messages
            'setFlash' => true,
        ]
    ];
}

// View文件中
// Pjax::begin();
GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        'id',
        [
            'class' => '\hbhe\grid\ToggleColumn',
            'attribute' => 'status',
            'action' => 'toggle-status',
            'onText' => '禁用',
            'offText' => '启用',
            'displayValueText' => true,
            'onValueText' => '已禁用',
            'offValueText' => '已启用',
            'iconOn' => 'stop',
            'iconOff' => 'stop',
            'enableAjax' => false, // 使用pjax时要设为true
            'confirm' => function($model, $toggle) {
                if ($model->status == Member::STATUS_NOT_ACTIVE) {
                    return "确认启用: {$model->username}({$model->id})?";
                } else {
                    return "确认禁用: {$model->username}({$model->id})?";
                }
            },
            'headerOptions' => array('style' => 'width:80px;'),
        ],
    ],
]);

// Pjax::end();
```

[![截图](https://github.com/hbhe/yii2-toggle-column/raw/master/screenshot.png)](https://github.com/hbhe/yii2-toggle-column/blob/master/screenshot.png)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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://avatars.githubusercontent.com/u/6417343?v=4)[hbhe](/maintainers/hbhe)[@hbhe](https://github.com/hbhe)

### Embed Badge

![Health badge](/badges/hbhe-yii2-toggle-column/health.svg)

```
[![Health](https://phpackages.com/badges/hbhe-yii2-toggle-column/health.svg)](https://phpackages.com/packages/hbhe-yii2-toggle-column)
```

PHPackages © 2026

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