Pregunta

I am trying to setup Sluggable from StofDoctrineExtensionsBundle to generate slug based primary key id and name field

/**
 * @var string
 * @Gedmo\Slug(fields={"id","name"})
 * @ORM\Column(name="slug", type="string", length=255, unique=true)
 */
private $slug;

However It doesn't generate like id-name, only generates slug based name. Why does it happen?

No hay solución correcta

Otros consejos

If your sluggable listener listens on Doctrine's prePersist operation ...

... then your entity does at that point not have an id because it was not yet persisted.

This explains the missing id in the slug.

Set SluggableListener to postPersist and it will work as desired.

Change Gedmo/Sluggable/SluggableListener's subscribed events to postPersist.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top