PHP code example of kinulab / sequence-generator-bundle
1. Go to this page and download the library: Download kinulab/sequence-generator-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/ */
kinulab / sequence-generator-bundle example snippets
php
public function registerBundles()
{
$bundles = array(
...
new Kinulab\SequenceGeneratorBundle\SequenceGeneratorBundle(),
);
}
php
use Kinulab\SequenceGeneratorBundle\Entity\CustomSequence;
use Kinulab\SequenceGeneratorBundle\Generator\SequenceGenerator;
// Enregistrement d'une nouvelle séquence
$sequence = new CustomSequence();
$sequence->setLibelle("Séquence des factures");
$sequence->setSequenceName("facture_seq");
$sequence->setIncrementBy(1);
$sequence->setIncrementLength(5);
$sequence->setPrefix('FC');
$sequence->setRestartYearly(true);
$em = $doctrine->getManager();
$em->persist($sequence);
$em->flush();
// Initialisation de la séquence
$generator = $container->get(SequenceGenerator::class);
$generator->initializeSequence($sequence);
// Utilisation
echo $generator->getNextVal('facture_seq'); // FC00001
echo $generator->getNextVal('facture_seq'); // FC00002
// On change le pas d'incrémentation
$sequence->setIncrementBy(2);
$generator->initializeSequence($sequence);
echo $generator->getNextVal('facture_seq'); // FC00004
echo $generator->getNextVal('facture_seq'); // FC00006