First, get Hashids.php and HashGenerator.php from http://www.hashids.org/php/ and put them in your app's Vendor/Hashids folder.
Then put HashidsComponent.php to your app's Controller/Component folder.
And lastly, add this to your AppController.php:
public $components = array ( // ... 'Hashids' => array ( 'salt' => 'YOUR_SALT_HERE', // Required 'min_hash_length' => 0, // Optional 'alphabet' => '', // Optional ) );
Use in your Controllers like this:
$encoded = $this->Hashids->encode(1, 2, 3);
Or in your Components, Views or anywhere else:
$encoded = HashidsComponent::encode(1, 2, 3);
By default, this component returns the first element of the resulting decode:
$this->Hashids->decode($encoded); // --> 1
If you wish to get an array instead, set the second parameter to
true, like this:
$this->Hashids->decode($encoded, true); // --> array(1, 2, 3);
Since v1.0.0, several public functions of Hashids were renamed to be more appropriate:
The component's method names were also changed to maintain consistency.