Translation Behaviour is looking for \Enti folder

梦想与她 提交于 2019-12-25 03:06:22

问题


I am trying to translate the slug of a BlogPost in multiple languages. I decided to use KnpLabs/DoctrineBehaviors to help me with the task. I installed the bundle, got the sluggable behaviour to work in minutes. However, when I add the translatable behaviour, I get can't update my schema.

I get the following error when I try to update my database schema (I know that the --force is not on the picture, but it does the same result).

Here's my BlogPost Entity :

namespace MyProject\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * @ORM\Entity
 */
class BlogPost
{  
    use ORMBehaviors\Sluggable\Sluggable,
        ORMBehaviors\Translatable\Translation;


    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }


    public function getSluggableFields()
    {
        return [ 'title' ];
    }

}

And here's my BlogPostTranslation entity :

namespace MyProject\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ORMBehaviors\Translatable\Translation;

/**
 * @ORM\Entity
 */
class BlogPostTranslation
{
    use ORMBehaviors\Translatable\Translation;


    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $name;


    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function getTitle()
    {
        return $this->title;
    }
}

I did some debugging with doctrine and the "TargetEntity" is really looking for a folder "Enti". This only occur if I add the translatable behaviour. If I remove it, I can update and use the sluggable behaviour without any problem.


回答1:


You problem lies within the BlogPost entity. You have to use the Translatable trait instead of the Translation trait.
To fix your issue change the use statement to:

/**
 * @ORM\Entity
 */
class BlogPost
{  
    use ORMBehaviors\Sluggable\Sluggable,
        ORMBehaviors\Translatable\Translatable;
    // ...

Also check out the section about proxy translations.



来源:https://stackoverflow.com/questions/22867913/translation-behaviour-is-looking-for-enti-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!