PHP code example of tourze / doctrine-random-bundle
1. Go to this page and download the library: Download tourze/doctrine-random-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/ */
tourze / doctrine-random-bundle example snippets
use Tourze\DoctrineRandomBundle\Attribute\RandomStringColumn;
class YourEntity
{
#[RandomStringColumn(prefix: 'user_', length: 20)]
private string $randomId;
public function getRandomId(): string
{
return $this->randomId;
}
public function setRandomId(string $randomId): self
{
$this->randomId = $randomId;
return $this;
}
}
$entity = new YourEntity();
$entityManager->persist($entity);
$entityManager->flush();
// $entity->getRandomId() will return something like 'user_a1b2c3d4e5f6g7h8i9'
// Create a new entity
$entity = new YourEntity();
// The randomId property will be automatically filled with a random string
// when the entity is persisted
$entityManager->persist($entity);
$entityManager->flush();
// Now $entity->getRandomId() will return something like 'user_a1b2c3d4e5f6g7h8i9'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.