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

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

bahirul/yii2-autonumber
=======================

Auto number extension for the Yii framework + Enhacement

1.6(7y ago)0376BSD-3-ClausePHP

Since Nov 2Pushed 11mo ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (8)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) with additional features.

Additional Features
-------------------

[](#additional-features)

- Ability to set db connection (for multiple databases)

```
public function behaviors()
{
	return [
		[
			'class' => 'bahirul\yii2\autonumber\Behavior',
            'db' => Yii::$app->db2, // set other database connection rather than default
			'attribute' => 'sales_num', // required
			'group' => $this->id_branch, // optional
			'value' => 'SA.'.date('Y-m-d').'.?' , // format auto number. '?' will be replaced with generated number or you can use " 'value' => function($event){ return 'SA.'.date('Y-m-d').'.?' } " as long the return value contain '?' character
			'digit' => 4 // optional, default to null.
		],
	];
}
```

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

[](#installation)

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

Either run

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

```

or add

```
"bahirul/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=@bahirul/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' => 'bahirul\yii2\autonumber\Behavior',
            'db' => Yii::$app->db2, // set other database connection rather than default
			'attribute' => 'sales_num', // required
			'group' => $this->id_branch, // optional
			'value' => 'SA.'.date('Y-m-d').'.?' , // format auto number. '?' will be replaced with generated number or you can use " 'value' => function($event){ return 'SA.'.date('Y-m-d').'.?' } " as long the return value contain '?' character
			'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').'.?'],
        ...
    ];
}
```

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

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 75.6% 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 ~229 days

Recently: every ~277 days

Total

7

Last Release

2834d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96498e0a3371c1580b9ed83580d8afa3a62ec565fc9329a9a6f25335135c3ea8?d=identicon)[bahirul](/maintainers/bahirul)

---

Top Contributors

[![mdmunir](https://avatars.githubusercontent.com/u/5828252?v=4)](https://github.com/mdmunir "mdmunir (31 commits)")[![bahirul](https://avatars.githubusercontent.com/u/8992466?v=4)](https://github.com/bahirul "bahirul (10 commits)")

---

Tags

yii2yii2-extensionyii2extensionBehavior autonumber

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/bahirul-yii2-autonumber/health.svg)](https://phpackages.com/packages/bahirul-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)
