سؤال

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?

لا يوجد حل صحيح

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top