PHPackages                             dynamikaweb/yii2-uuid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dynamikaweb/yii2-uuid

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

dynamikaweb/yii2-uuid
=====================

Guide and package for using UUID in yii2 projects

1.1(4y ago)01.3k↑30.4%BSD-3-ClausePHPPHP &gt;=7.4.0

Since Apr 20Pushed 4y agoCompare

[ Source](https://github.com/dynamikaweb/yii2-uuid)[ Packagist](https://packagist.org/packages/dynamikaweb/yii2-uuid)[ RSS](/packages/dynamikaweb-yii2-uuid/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

dynamikaweb/yii2-uuid
=====================

[](#dynamikawebyii2-uuid)

[![Latest Stable Version](https://camo.githubusercontent.com/c4931696a9f00d555f8a6199aa774de98eacbfa99ea2233f514171583fd0b3b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f64796e616d696b617765622f796969322d75756964)](https://github.com/dynamikaweb/yii2-uuid/releases)[![Total Downloads](https://camo.githubusercontent.com/efc0877ff053914b5f9092ef970f07ff85d81e6679509817e1f9ed50a87c097a/68747470733a2f2f706f7365722e707567782e6f72672f64796e616d696b617765622f796969322d757569642f646f776e6c6f616473)](https://packagist.org/packages/dynamikaweb/yii2-uuid)[![License](https://camo.githubusercontent.com/56a6a460239be38efae47696412e2875c0aff96df30d8b6537629e4810690d0d/68747470733a2f2f706f7365722e707567782e6f72672f64796e616d696b617765622f796969322d757569642f6c6963656e7365)](https://github.com/dynamikaweb/yii2-uuid/blob/master/LICENSE.txt)[![Codacy Badge](https://camo.githubusercontent.com/fd206b807a8325076b441720777ae3ada690712511d928b9cacb6ac8b5bcb357/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3761663064653738613035313461623562656462303230663337343931393864)](https://www.codacy.com/gh/dynamikaweb/yii2-uuid/dashboard?utm_source=github.com&utm_medium=referral&utm_content=dynamikaweb/yii2-uuid&utm_campaign=Badge_Grade)[![Build Test](https://camo.githubusercontent.com/0da596c1257cb71f9c6c4739290d4927ed51de34f7b13174f1c4bf139e23f82c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64796e616d696b617765622f796969322d757569642f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dynamikaweb/yii2-uuid/)[![Latest Unstable Version](https://camo.githubusercontent.com/43f400ced94ff84cbce0bdbae81abc7d055f7e209704b8991aa3c20d6b95afca/68747470733a2f2f706f7365722e707567782e6f72672f64796e616d696b617765622f796969322d757569642f762f756e737461626c65)](https://github.com/dynamikaweb/yii2-uuid/find/master)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require dynamikaweb/yii2-uuid "*"
```

or add

```
"dynamikaweb/yii2-uuid": "*"
```

to the `require` section of your `composer.json` file.

Database usage
--------------

[](#database-usage)

### Create migration

[](#create-migration)

```
public function safeUp()
{
    $this->addColumn('sometable', 'uuid', 'uuid' => $this->binary(16)->unique()->notNull());
    $this->createIndex('sometable_uuid_idx', 'sometable', 'uuid');
    ...
}
```

Model usage
-----------

[](#model-usage)

### Validate

[](#validate)

```
use dynamikaweb\uuid\UuidValidator;
public function rules()
{
    return [
        [['uuid'], UuidValidator::classname(), 'on' => self::SCENARIO_SEARCH]
        ...
    ];
}
```

### Generate and save

[](#generate-and-save)

```
use dynamikaweb\uuid\Uuid;
public function beforeSave($insert)
{
    if (!parent::beforeSave($insert)) {
        return false;
    }

    if ($this->isNewRecord) {
        $this->setAttribute('uuid', Uuid::uuid4()->getBytes());
    }
    ...
}
```

### Formatting to string

[](#formatting-to-string)

```
public function getUuidToString()
{
    if (is_resource($this->uuid)) {
        $this->uuid = stream_get_contents($this->uuid);
    }

    return Uuid::fromBytes($this->uuid)->toString();
}
```

Controller usage
----------------

[](#controller-usage)

### View

[](#view)

```
public function actionView($uuid)
{
    return $this->render('view', [
        'model' => $this->findModel($uuid)
    ]);
}
```

### Finding

[](#finding)

```
protected function findModel($uuid)
{
    try {
        $uuid = '\x'.bin2hex(Uuid::fromString($uuid)->getBytes());
    }
    catch (InvalidUuidStringException $e) {
        throw new HttpException(400, 'UUID invalid!');
    }
    if (($model = SomeModel::findOne(['uuid' => $uuid])) === null) {
        throw new HttpException(404, 'UUID not found!');
    }

    return $model;
}
```

View usage
----------

[](#view-usage)

### Form

[](#form)

```
use dynamikaweb\uuid\UuidMask;

echo UuidMask::widget([
    'name' => 'uuid'
]);
```

### Active form

[](#active-form)

```
echo $form->field($model, 'from_date')->widget(Uuid::className());
```

###  Health Score

27

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Total

2

Last Release

1593d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/da2fcbacce6bf394ac817392af1c39dd7b1bbe8411f5adc8caa485d8f7454f26?d=identicon)[RodrigoDornelles](/maintainers/RodrigoDornelles)

---

Top Contributors

[![RodrigoDornelles](https://avatars.githubusercontent.com/u/29123479?v=4)](https://github.com/RodrigoDornelles "RodrigoDornelles (5 commits)")[![robsondrs](https://avatars.githubusercontent.com/u/53342735?v=4)](https://github.com/robsondrs "robsondrs (1 commits)")

---

Tags

uuidyii2

### Embed Badge

![Health badge](/badges/dynamikaweb-yii2-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/dynamikaweb-yii2-uuid/health.svg)](https://phpackages.com/packages/dynamikaweb-yii2-uuid)
```

###  Alternatives

[thamtech/yii2-uuid

Yii 2 UUID Helper

35341.5k7](/packages/thamtech-yii2-uuid)[brussens/yii2-maintenance-mode

Maintenance mode component for Yii framework 2.x.x version.

78253.9k5](/packages/brussens-yii2-maintenance-mode)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1356.4k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
