Symfony – how to combine translatable and sluggable in doctrine extensions?

I have installed https://github.com/stof/StofDoctrineExtensionsBundle And use translatable and sluggable on specific fields of the country entity:

...
class Country
{
    ...
    /**
     * @Gedmo\Translatable
     * @Gedmo\Slug(fields={"name"})
     * @ORM\Column(length=255,nullable=false)
     */
    private $slug;

For English users, the URL of the page should be... / country / France; For German speaking users, the URL of the page should be... / land / frankreich

In a controller, I get a language specific slug and filter it through the locale specific slug. I want to retrieve a state entity

I don't find anything here or in the documentation on how to do this

Thank you for any tips on how to solve this problem!

Solution

Just found solution in this blog article The solution is to use translation Walker's ORM query prompt to automatically join the transformation table, so you can sort or filter by any translation field This is great!

Then the code looks like:

...
->createQuery('SELECT...FROM MyFooBundle:Country c WHERE c.slug = :slug...)
->setParameter('slug',$slug)
->setHint(
    \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
)
->getSingleResult();

By the way: if you want to use fallback (i.e. if no specific translation is available, use the default string / text), then call settranslationfallback method (in doctrine_extensions.yml) for your gedmo listener. The translatable service configures it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>