我已阅读Gedmo Doctrine Extensions - Sluggable + Translatable Yaml Configuration和https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md#using-translationlistener-to-translate-our-slug
我仍然无法上班。翻译适用于我设置的所有其他字段,但它不适用于slug。
我错过了什么吗?
我已将sluggable listener的优先级设置为1
/MyBundle/config/services.yml
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: default, priority: 1 }
calls:
- [ setAnnotationReader, [ @annotations.cached_reader] ]
/MyBundle/Entity/MyEntity.php
/**
* @Gedmo\Translatable
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(length=64, unique=true, nullable=false)
*/
private $slug;
/**
* @Gedmo\Locale
*
*/
protected $locale;
public function setTranslatableLocale($locale){
$this->locale = $locale;
}
默认语言区域为' de'。
/MyBundle/Controller/MyController.php
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
$object = $em->getRepository('MyEntity')->find($id)
$evm = new EventManager();
$sluggableListener = new SluggableListener();
$evm->addEventSubscriber($sluggableListener);
$translatableListener = new TranslatableListener();
$translatableListener->setTranslatableLocale('en');
$evm->addEventSubscriber($translatableListener);
$object->setTranslatableLocale('en);
$em->refresh($object);
$em->persist($object);
$em->flush;
.....