PHP code example of bahirul / yii2-autonumber

1. Go to this page and download the library: Download bahirul/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/ */

    

bahirul / yii2-autonumber example snippets


public function behaviors()
{
	return [
		[
			'class' => 'bahirul\yii2\autonumber\Behavior',
			'attribute' => 'sales_num', // d 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'

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

php composer.phar