Made for Symfony ^2.7 and also ^3.0
composer require lsv/hashidsbundle
or add it your composer.json
"require": {
"lsv/hashidsbundle": "^1.0"
}
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new \Lsv\HashidsBundle\LsvHashidsBundle(),
);
}
All configuration is optional, but this is the configuration availible
lsv_hashids:
# Salt is default the same as your app secret
salt: "%secret%"
# Length is default 8
length: 8
# Alphabet is default "abcdefghij1234567890" - Default in hashids
alphabet: "abcdefghij1234567890"
In your controller you can use
$this->get('lsv_hashids')->encode($id);
$this->get('lsv_hashids')->decode($string);
Also added 3 twig methods
id | hashids
id | encode_hashids
string | decode_hashids