wartron/yii2-uuid
Composer 安装命令:
composer require wartron/yii2-uuid
包简介
Yii2 UUID Helpers
关键字:
README 文档
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;
统计信息
- 总下载量: 4.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-20