Question

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 correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top