PHP code example of chamber-orchestra / doctrine-slug-bundle

1. Go to this page and download the library: Download chamber-orchestra/doctrine-slug-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/ */

    

chamber-orchestra / doctrine-slug-bundle example snippets


// config/bundles.php
return [
    ChamberOrchestra\DoctrineSlugBundle\ChamberOrchestraDoctrineSlugBundle::class => ['all' => true],
];

namespace App\Entity;

use ChamberOrchestra\DoctrineSlugBundle\Mapping\Attribute\Slug;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Post
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 255)]
    private string $name = '';

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    #[Slug(source: 'name')]
    private string $slug = '';

    // getters ...
}

use ChamberOrchestra\DoctrineSlugBundle\Contracts\Entity\SlugInterface;
use ChamberOrchestra\DoctrineSlugBundle\Entity\SlugTrait;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Post implements SlugInterface
{
    use SlugTrait;

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;
}