PHP code example of jimchen / yii2-hashids

1. Go to this page and download the library: Download jimchen/yii2-hashids library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jimchen / yii2-hashids example snippets


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' => [
        '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]