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

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

bhoft/yii2-autonumber
=====================

Auto number extension for the Yii framework

1.5(7y ago)06BSD-3-ClausePHP

Since Nov 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Bhoft/yii2-autonumber)[ Packagist](https://packagist.org/packages/bhoft/yii2-autonumber)[ RSS](/packages/bhoft-yii2-autonumber/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (7)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.

This extension forked from [mdm/yii2-autonumber](https://github.com/mdmsoft/yii2-autonumber) and extended with some modifications.

modifications: `targetClass` attribute so the extension could also be used with different extended classes e.g. MyModel, MyModelForm and still get the same autonumber `group` could be now an model attribute or function or class function `format` set the format of the autonumber `db` to set a different database

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

[](#installation)

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

Either run

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

```

or add

```
"bhoft/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=@bhoft/yii2/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' => 'bhoft\yii2\autonumber\Behavior',
			'targetClass' => 'app\models\MyModel',  // optional default OwnerClassname
			'attribute' => 'sales_num', // required
			'group' => 'groupAttribute', // optional
				// or as class function
	            // 'group' => array($this, 'getGroupId'),  //
	            // or
	            // 'group' => $this->groupId'),  //
			'format' => 'SA.'.date('Y-m-d').'.?' , // format auto number. '?' will be replaced with generated number
				//you could also use " 'format' => function($event){ return 'SA.'.date('Y-m-d').'.?' } "
			'digit' => 4 // optional, default to null.
			//'db' => Yii::app()->db,  // optional
		],
	];
}

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

Instead of behavior, you can use this extension as validator

```
use bhoft\autonumber\AutonumberValidator;
...
public function rules()
{
    return [
        [['sales_num'], AutonumberValidator::className(), 'format'=>'SA.'.date('Y-m-d').'.?'],
        ...
        [['submission_num'], AutonumberValidator::className(), 'format'=>'?', 'targetClass' => 'app\models\MyModel', 'group' => 'call_id'],
    ];
}
```

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% 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 ~325 days

Recently: every ~341 days

Total

6

Last Release

2582d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0783b8dff0df27fccb973a5a2bff2a12d9f1a570d1f17d9a527211ebcf050903?d=identicon)[Bhoft](/maintainers/Bhoft)

---

Top Contributors

[![mdmunir](https://avatars.githubusercontent.com/u/5828252?v=4)](https://github.com/mdmunir "mdmunir (31 commits)")[![Bhoft](https://avatars.githubusercontent.com/u/1777147?v=4)](https://github.com/Bhoft "Bhoft (2 commits)")

---

Tags

yii2extensionBehavior autonumber

### Embed Badge

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

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

###  Alternatives

[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1830.9k](/packages/mdmsoft-yii2-autonumber)[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)
