PHP code example of aracoool / yii2-uuid

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

    

aracoool / yii2-uuid example snippets


use \aracoool\yii2-uuid\UuidBehavior

/**
 * @return array
 */
public function behaviors()
{
    return [
        [
            'class' => UuidBehavior::class,
            'version' => Uuid::V4
        ],
        ...
    ];
}

use \aracoool\yii2-uuid\UuidBehavior

/**
 * @return array
 */
public function behaviors()
{
    return [
        [
            'class' => UuidBehavior::class,
            'version' => Uuid::V3, // Uuid::V5
            'namespace' => Uuid::NAMESPACE_NIL,
            'nameAttribute' => 'title' // Value of this attribute SHOULD be unique in your database
        ],
        ...
    ];
}

use \aracoool\yii2-uuid\Uuid

Uuid::v3(Uuid::NAMESPACE_URL, 'http://example.com/');
Uuid::v5(Uuid::NAMESPACE_DSN, 'www.google.com');
Uuid::v3(Uuid::NAMESPACE_OID, '1.3.6.1');
Uuid::v5(Uuid::NAMESPACE_X500, 'c=ca');
Uuid::v4();

use \aracoool\yii2-uuid\UuidValidator;

/**
 * @return array
 */
 public function rules()
 {
     return [
         ...
         ['attribute_id', UuidValidator::class],
         ...
     ];
 }