Symfony + Gedmo Doctrine with translatable slug

时间:2015-11-26 09:19:28

标签: php symfony doctrine-orm

我已阅读Gedmo Doctrine Extensions - Sluggable + Translatable Yaml Configurationhttps://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;

    .....

0 个答案:

没有答案