Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - translatable field - The class 'Gedmo\Translatable\Entity\Translation' was not found in the chain configured namespaces

I'm trying to translate some fields of my entity and I have the following error when I'm try create an object...

<?php

namespace XXXX\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Line
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="XXXX\Entity\LineRepository")
 */
class Line implements Translatable
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Line
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }
}

And the error:

[Doctrine\Common\Persistence\Mapping\MappingException]
The class 'Gedmo\Translatable\Entity\Translation' was not found in the chain configured namespaces

I'm using Symfony 2.5, but in 2.4 occurs too. Any idea how I can solve this?

like image 802
David Avatar asked Jun 25 '14 09:06

David


2 Answers

You need to configure the translatable Entity to use as well. In config.yml:

orm:
    (....)
    mappings:
        translatable:
            type: annotation
            is_bundle: false
            prefix: Gedmo\Translatable\Entity
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
            alias: GedmoTranslatable
like image 83
wadoo Avatar answered Sep 27 '22 02:09

wadoo


Update for Symfony 5 : Configure the /config/packages/doctrine.yaml file and add the following

orm:
    (....)
    mappings:
        translatable:
            type: annotation
            is_bundle: false
            prefix: Gedmo\Translatable\Entity
            dir: '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity'
            alias: GedmoTranslatable
like image 27
Julien Haegman Avatar answered Sep 24 '22 02:09

Julien Haegman