PHP code example of roukmoute / hashids-bundle

1. Go to this page and download the library: Download roukmoute/hashids-bundle 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/ */

    

roukmoute / hashids-bundle example snippets




return [
    …,
    Roukmoute\HashidsBundle\RoukmouteHashidsBundle::class => ['all' => true],
];


use Hashids\HashidsInterface;

public function postShow(HashidsInterface $hashids): Response
{
    $hashids->…
}

use Roukmoute\HashidsBundle\Attribute\Hashid;
use Symfony\Component\Routing\Attribute\Route;

#[Route('/posts/{id}')]
public function show(#[Hashid] int $id): Response
{
    // $id is automatically decoded from the hashid
}

#[Route('/posts/{hash}')]
public function show(#[Hashid(parameter: 'hash')] int $id): Response
{
    // The 'hash' route parameter is decoded into $id
}

#[Route('/users/{hashid}')]
public function getAction(int $user): Response
{
}

#[Route('/users/{id}')]
public function getAction(int $user): Response
{
}

#[Route('/users/{_hash_user}/status/{_hash_status}')]
public function getAction(int $user, int $status): Response
{
}

//                          _hash_user  _hash_status
//                                 ↕            ↕
public function getAction(int $user, int $status)

#[Route('/users/{user}/status/{status}')]
public function getAction(int $user, int $status): Response
{
}

#[Route('/users/{hashid}')]
public function getAction(User $user): Response
{
}