wartron/yii2-uuid

Yii2 UUID Helpers

Installs: 4 700

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 2

Forks: 2

Open Issues: 1

Type:yii2-extension

dev-master 2015-09-20 21:38 UTC

This package is not auto-updated.

Last update: 2024-05-25 16:23:00 UTC


README

Helpers for using uuids as primary keys.

Installation

Add the uuid behavior to models.

We could use the SqlExpression to generate the uuid in sql, but we dont get the ID back in last insert id. (We can get around this with triggers if you want a pure SQL method). But generating the ID UUID in php we dont need to worry about getting the id an refreshing the model.

Using our UUID'd ActiveRecord, it will take care of generating the id, and can handle toArray for api calls repersenting the uuid and other uuid fields as in hex.

use wartron\yii2uuid\db\ActiveRecord;

Using the Behavior for id.

public function behaviors()
{
    return [
        \wartron\yii2uuid\behaviors\UUIDBehavior::className(),
    ];
}

To use the formater asHex

'components' => [
    'formatter' => [
        'class' => '\wartron\yii2uuid\components\Formatter'
    ],
]

The Helper providers access to ramsey/uuid. This will automaticly convert to the binary from we use!

use wartron\yii2uuid\helpers\Uuid;

//generate uuids
Uuid::uuid1();
Uuid::uuid3();
Uuid::uuid4();
Uuid::uuid5();

//converting
Uuid::str2uuid($hexString);
Uuid::uuid2str($binary);

To use the rest ActiveControllers use the provided ActiveController instead of yii\rest\ActiveController

use wartron\yii2uuid\rest\ActiveController;