翻译行为正在寻找\Enti文件夹 [英] Translation Behaviour is looking for \Enti folder

查看:214
本文介绍了翻译行为正在寻找\Enti文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用多种语言翻译BlogPost的。。。我决定使用KnpLabs / DoctrineBehaviors帮助我完成任务。我安装了捆绑包,几分钟就得到了可耻的行为。但是,当我添加可翻译的行为时,我无法更新我的模式。

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.

当我尝试更新我的数据库模式时,我收到以下错误(我知道--force不在图片上,但效果不错)。

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).

这是我的BlogPost实体:

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' ];
    }

}

这里是我的BlogPostTranslation实体: / p>

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;
    }
}

我用doctrine和TargetEntity真的是找一个文件夹Enti。 仅当我添加可翻译行为时才会发生。如果我删除它,我可以更新和使用sluggable行为没有任何问题。

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.

推荐答案

您的问题在于 BlogPost 实体。您必须使用 可翻译 trait而不是翻译特征。

要解决您的问题,请将使用语句更改为:

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;
    // ...

同时查看有关代理翻译

这篇关于翻译行为正在寻找\Enti文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆