PHPackages                             ancor/yii2-constant-label - 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. ancor/yii2-constant-label

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

ancor/yii2-constant-label
=========================

Create labels for any model constants

0225PHP

Since Mar 12Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ancor-dev/yii2-constant-label)[ Packagist](https://packagist.org/packages/ancor/yii2-constant-label)[ RSS](/packages/ancor-yii2-constant-label/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Allow to specify labels for constants in a Model
================================================

[](#allow-to-specify-labels-for-constants-in-a-model)

Feel free to let me know what else you want added via:

- [Issues](https://github.com/ancor-dev/yii2-constant-label/issues)

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

[](#installation)

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

Either run

```
$ php composer.phar require ancor/yii2-constant-label
```

or add

```
"ancor/yii2-constant-label": "dev-master"

```

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

Adding to the model
-------------------

[](#adding-to-the-model)

To use ConstantLabelBehavior, insert the following code to your Model class:

```
use common\behaviors\ConstantLabelBehavior;

/**
 * @mixin ConstantLabelBehavior
 */
class MyModel extends Model
{
    const STATUS_ACTIVE  = 10;
    const STATUS_DELETED = 0;

    public function behaviors()
    {
      return [
          [
              'class' => ConstantLabelBehavior::className(),
              'constantLabels' => [
                  'status' => [
                      self::STATUS_ACTIVE  => 'User is active',
                      self::STATUS_DELETED => 'User deleted',
                  ]
              ],
          ]
      ];
    }
}
```

Usage
-----

[](#usage)

```
$model = new MyModel();

// return key-value array with constant values as key and constant label as value
$labels = $model->getConstantLabels('status');

// return label for one constant
$label = $model->getConstant('status', $model::STATUS_ACTIVE);

// return values of all constants
$values = $model->getConstantValues('status'); // [10, 0]

// also it can be use in validation rules
[
    ['status', 'in', 'range' => $model->getConstantValues('status')],
]
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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/11b715dbbb813e6d3cd3c1bba6a6f7b8af7ffb0aa9d1b1a46a11910a2c41cb45?d=identicon)[ancor.dev](/maintainers/ancor.dev)

### Embed Badge

![Health badge](/badges/ancor-yii2-constant-label/health.svg)

```
[![Health](https://phpackages.com/badges/ancor-yii2-constant-label/health.svg)](https://phpackages.com/packages/ancor-yii2-constant-label)
```

###  Alternatives

[lekoala/silverstripe-cms-actions

Add actions to your models in SilverStripe

39317.0k29](/packages/lekoala-silverstripe-cms-actions)[jeffreyvr/dropblockeditor

A simple block editor made with Livewire.

1236.6k1](/packages/jeffreyvr-dropblockeditor)

PHPackages © 2026

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