light / hashids
适用于 Yii2 的 Hashids
2.0.0
2018-02-28 15:22 UTC
Requires
- php: ^5.6.4 || ^7.0
- hashids/hashids: ^2.0
- yiisoft/yii2: ~2.0.14
Requires (Dev)
- phpunit/phpunit: ^6.0
README
Yii2 Hashids
注意:2.0 版本的 master 分支需要最低 PHP 版本为 5.6。您可以通过 light/hashids:^1.0
来使用旧版本。
安装
通过 Composer 安装此包
$ composer require light/hashids=^2.0
用法
配置为组件
在您的 main.php
或 web.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