The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mdmsoft/yii2-autonumber "*"
or add
"mdmsoft/yii2-autonumber": "*"
to the require section of your composer.json
file.
Prepare required table by execute yii migrate.
yii migrate --migrationPath=@mdm/autonumber/migrations
Once the extension is installed, simply modify your active record definision class:
public function behavior()
{
return [
[
'class' => 'mdm\autonumber\Behavior',
'attribute' => 'sales_num', // required
'group' => 'sales', // required, unique
'value' => 'SA-'.date('Y-m-d').'?' , // format auto number. '?' will be replaced with generated number
'digit' => 4 // optional, default to null.
],
...
];
}