PHP code example of bhoft / yii2-autonumber

1. Go to this page and download the library: Download bhoft/yii2-autonumber library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bhoft / yii2-autonumber example snippets


public function behaviors()
{
	return [
		[
			'class' => 'bhoft\yii2\autonumber\Behavior',
			'targetClass' => 'app\models\MyModel',  // optional default OwnerClassname
			'attribute' => 'sales_num', // 	'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'


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'],
    ];
}

php composer.phar