19/02/2016 - PHP, SYMFONY
If you want to creating friendly ID from integer values in symfony the use example below. Example uses Hashids library.
Install "hashids/hashids": "^1.0"
with composer.
You should put variables in parameters.yml and create a util class as a service for this example. My example below is a shortcut and bad practise.
public function test($id)
{
$salt = '35b9d8914020276ba992d112ee7c68022d49d85e';
$minIdLength = 10;
$alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$hashids = new Hashids($salt, $minIdLength, $alphabet);
$encodedId = $hashids->encode($id);
$decodedId = $hashids->decode($encodedId);
echo 'ENCODED:', $encodedId, ' - DECODED:', $decodedId[0];
}
$this->test(1);
# Prints
ENCODED:KV8O4GBYPE - DECODED:1