Hashids for Yii framework
$ 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
],
],
];
the connections
should defined like:
[
...
'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