I have just installed the doctrine extensions to use Sluggable.
I make this :
composer.json
"stof/doctrine-extensions-bundle": "1.2.*@dev"
AppKernel.php
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
app/config/config.yml
stof_doctrine_extensions:
orm:
default:
sluggable: true
Djoo\AppliBundle\Entity\Nomenclature.php
namespace Djoo\AppliBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\SmallIntType;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Nomenclature
*
*
* @ORM\Table(name="app_nomenclature")
* @ORM\Entity
*/
class Nomenclature
{
.....
/**
* @var string
*
* @ORM\Column(name="titre", type="string", length=200, nullable=false)
*/
private $titre;
/**
* @var string
*
* @ORM\Column(name="finess", type="string", length=10, nullable=true)
*/
private $finess;
/**
* @Gedmo\Slug(fields={"titre","finess"},suffix=".html")
* @ORM\Column(length=128, unique=true,nullable=true)
*/
private $slug;
public function getSlug() {
return $this->slug;
}
public function setSlug($slug){
$this->slug = $slug;
return $this;
}
}
In my controller i make this to generate slug for old values in my datatable :
$filterBuilder = $this->get('doctrine.orm.entity_manager')>getRepository('DjooAppliBundle:Nomenclature')->createQueryBuilder('e')->orderBy('e.titre', 'asc');
$query = $filterBuilder->getQuery();
$nomenclatures = $query->getResult();
foreach($nomenclatures as $nomenclaturee){
$nomenclature->setSlug(null);
$this->get('doctrine.orm.entity_manager')->persist($nomenclature);
$this->get('doctrine.orm.entity_manager')->flush();
}
I have no error, but my old values are a null slug. I try to create a new element and i have a good slug. Have you and idea ?
Thanks