jimchen/yii2-hashids

Hashids for Yii framework

Maintainers

👁 jimchen

Package info

github.com/JimChenWYU/yii2-hashids

pkg:composer/jimchen/yii2-hashids

Statistics

Installs: 1 299

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 1

0.1.0 2018-08-29 08:01 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT bd6eb61ee329a317373cc2fb67fc56fe81d77ccc

  • JimChen <18219111672.woop@163.com>

This package is auto-updated.

Last update: 2026-06-05 23:03:36 UTC


README

Hashids for Yii framework

Installing

$ composer require jimchen/yii2-hashids -vvv

Usage

Configure application components as follows

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 in your code as follows(it use the default channel.)

use Yii;

$encode = Yii::$app->hashids->encode(12345);

var_dump(Yii::$app->hashids->decode($encode)); // [12345]

Use other channel

use Yii;

$otherChannelHashids = \Yii::createObject('hashids.manager')->connection('channel name');

$encode = $otherChannelHashids->encode(12345);

var_dump($otherChannelHashids->decode($encode)); // [12345]

License

MIT