light/hashids

适用于 Yii2 的 Hashids

2.0.0 2018-02-28 15:22 UTC

This package is auto-updated.

Last update: 2024-09-08 19:07:44 UTC


README

Yii2 Hashids


Build Status version Download Issues

注意:2.0 版本的 master 分支需要最低 PHP 版本为 5.6。您可以通过 light/hashids:^1.0 来使用旧版本。

安装

通过 Composer 安装此包

$ composer require light/hashids=^2.0

用法

配置为组件

在您的 main.phpweb.php 文件中(依赖于您的 yii2 项目构造函数)

[
	'hahsids' => [
		'class' => 'light\hashids\Hashids',
		//'salt' => 'your salt',
		//'minHashLength' => 5,
		//'alphabet' => 'abcdefghigk'
	]
]

也可以这样使用

$hashids = Yii::createObject([
	'class' => 'light\hashids\Hashids'
]);

$id = $hashids->encode(1, 2, 3);
$numbers = $hashids->decode($id);
var_dump($id, $numbers);

测试

$ phpunit

许可证

MIT

Bitdeli Badge