jimchen / yii2-hashids
Yii 框架的 Hashids
0.1.0
2018-08-29 08:01 UTC
Requires
- php: >=5.5
- hashids/hashids: ~1.0
- yiisoft/yii2: ~2.0
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is auto-updated.
Last update: 2024-09-05 19:17:06 UTC
README
Yii 框架的 Hashids
安装
$ composer require jimchen/yii2-hashids -vvv
使用
按以下方式配置应用程序组件
return [ //... 'components' => [ //... 'hashids' => [ 'class' => 'jimchen\hashids\HashidsComponent', 'salt' => 'default channel salt', 'length' => 'default channel length of the encode string', // 'default' => 'main' // default channel // 'connections' => null // other channel ], ], ];
connections
应定义如下
[ ... 'connections' => [ 'channel name' => [ 'salt' => 'the salt', 'length' => 'the length of the encode string', ], ... ] ]
在您的代码中使用如下(使用默认通道)
use Yii; $encode = Yii::$app->hashids->encode(12345); var_dump(Yii::$app->hashids->decode($encode)); // [12345]
使用其他通道
use Yii; $otherChannelHashids = \Yii::createObject('hashids.manager')->connection('channel name'); $encode = $otherChannelHashids->encode(12345); var_dump($otherChannelHashids->decode($encode)); // [12345]
许可证
MIT