PHPackages                             mdmsoft/yii2-autonumber - 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. mdmsoft/yii2-autonumber

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

mdmsoft/yii2-autonumber
=======================

Auto number extension for the Yii framework

1.5.2(6y ago)1830.9k—0%18[1 issues](https://github.com/mdmsoft/yii2-autonumber/issues)BSD-3-ClausePHP

Since Nov 2Pushed 6y ago5 watchersCompare

[ Source](https://github.com/mdmsoft/yii2-autonumber)[ Packagist](https://packagist.org/packages/mdmsoft/yii2-autonumber)[ RSS](/packages/mdmsoft-yii2-autonumber/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (0)

Auto Number Extension for Yii 2
===============================

[](#auto-number-extension-for-yii-2)

Yii2 extension to genarete formated autonumber. It can be used for generate document number.

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist mdmsoft/yii2-autonumber "~1.0"

```

or add

```
"mdmsoft/yii2-autonumber": "~1.0"

```

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

Usage
-----

[](#usage)

Prepare required table by execute yii migrate.

```
yii migrate --migrationPath=@mdm/autonumber/migrations

```

if wantn't use db migration. you can create required table manually.

```
CREATE TABLE auto_number (
    "group" varchar(32) NOT NULL,
    "number" int,
    optimistic_lock int,
    update_time int,
    PRIMARY KEY ("group")
);
```

Once the extension is installed, simply modify your ActiveRecord class:

```
public function behaviors()
{
    return [
        [
            'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'sales_num', // required
    		'group' => $this->id_branch, // optional
    		'value' => 'SA.'.date('Y-m-d').'.?' , // format auto number. '?' will be replaced with generated number
    		'digit' => 4 // optional, default to null.
    	],
    ];
}

// it will set value $model->sales_num as 'SA.2014-06-25.0001'
```

Instead of behavior, you can use this extension as validator

```
public function rules()
{
    return [
        [['sales_num'], 'autonumber', 'format'=>'SA.'.date('Y-m-d').'.?'],
        ...
    ];
}
```

New Format
----------

[](#new-format)

Since version 1.5 we introduce new format of number. Now we use `{}` to evaluate as date and number of digit represented as number of `?`.

```
public function rules()
{
    return [
        [['sales_num'], 'autonumber', 'format' => 'SA/{Y/m}/?.???'],
        ...
    ];
}

// it will set value $model->sales_num as 'SA/2019/10/0.001'

public function behaviors()
{
    return [
        [
            'class' => 'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'sales_num', // required
            'value' => 'SA/{Y/m}/?.???'
        ]
    ];
}

// another usage

public function actionCreate()
{
    $model = new Sales()
    $model->load(Yii::$app->request->post());
    $model->sales_num = mdm\autonumber\AutoNumber::generate('SA/{Y/m}/?.???');
    ...
}
```

- [Api Documentation](http://mdmsoft.github.io/yii2-autonumber/index.html)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 97.4% 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.

###  Release Activity

Cadence

Every ~263 days

Recently: every ~346 days

Total

8

Last Release

2365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a5ba97416867dd2bff6c4e2fcd0e52f8b1f8bb7521dcef6b734636009ce834e?d=identicon)[mdmunir](/maintainers/mdmunir)

---

Top Contributors

[![mdmunir](https://avatars.githubusercontent.com/u/5828252?v=4)](https://github.com/mdmunir "mdmunir (38 commits)")[![deviardn](https://avatars.githubusercontent.com/u/6567330?v=4)](https://github.com/deviardn "deviardn (1 commits)")

---

Tags

yii2extensionBehavior autonumber

### Embed Badge

![Health badge](/badges/mdmsoft-yii2-autonumber/health.svg)

```
[![Health](https://phpackages.com/badges/mdmsoft-yii2-autonumber/health.svg)](https://phpackages.com/packages/mdmsoft-yii2-autonumber)
```

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

3030.6k](/packages/sjaakp-yii2-taggable)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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