I'm using JMS\I18nRoutingBundle
, Gedmo\Translatable
and Gedmo\Sluggable
. Routes with default locations works as well, but other locales works without translated slug. My i18n routing have following settings:
# Doctrine extensions
stof_doctrine_extensions:
default_locale: %locale%
translation_fallback: true
orm:
default:
#…
sluggable: true
translatable: true
loggable: false
#…
jms_i18n_routing:
default_locale: cs_CZ
locales: [cs_CZ, en_US]
strategy: custom
hosts:
cs_CZ: example.cz
en_US: example.com
redirect_to_host: true
When I set up route like this:
hw_category:
pattern: /category/{slug}
defaults: { _controller: AcmeSiteBundle:Category:detail }
/**
* @Template
*/
public function detailAction(Category $category)
{}
This routes worksexample.cz/category/slug-in-czech
example.com/category/slug-in-czech
But I want to get work example.com/category/slug-in-english
which throws 404 exception object not found
.
In your controller, you have to override method used in entity repository:
/**
* @Template
* @ParamConverter(
* "category",
* class = "AcmeSiteBundle:Category",
* options = {
* "repository_method" = "findByTranslatedSlug"
* }
* )
*/
public function detailAction(Category $category)
{}
namespace Acme\Bundle\SiteBundle\Entity;
use Doctrine\ORM\EntityRepository;
class CategoryRepository extends EntityRepository
{
public function findByTranslatedSlug($slug)
{
$qb = $this->createQueryBuilder('c')
->where('c.slug = :slug')
->setParameters($slug);
$query = $qb->getQuery();
// set the translation query hint
$query->setHint(
\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);
return $query->getOneOrNullResult();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With