Knp \ DoctrineBehaviors + a2lix_translations + Sonata Admin

时间:2014-11-25 21:11:47

标签: symfony doctrine-orm sonata-admin a2lix-translation

我将我的实体设置为https://github.com/KnpLabs/DoctrineBehaviors#translatable。同样配置为http://a2lix.fr/bundles/translation-form/。我还添加了__call方法并尝试实现How to print translatable data in sonata admin with DoctrineBehaviors from kpnlabs。首先,我得到的错误是$ name并不存在于Category.php中。所以我添加它,现在我有错误:  Neither the property "name" nor one of the methods "addName()"/"removeName()", "setName()", "name()", "__set()" or "__call()" exist and have public access in class。 问题是他们如何从主要实体中删除setter / getters,对我来说它导致了错误。也许某人对所有这些都有适当的魔力?

Category.php

class MyClass
{

    use \Knp\DoctrineBehaviors\Model\Translatable\Translatable;

    private $name; //added after error

    public function __call($method, $arguments)
    {
        return $this->proxyCurrentLocaleTranslation($method, $arguments);
    }

    public function getName() {
        return $this->translate()->getName(); //added after error
    }

    #public function getName() {
     #   return ($this->getTranslations()); // also trying like this
    #}

    // ...

CategoryTranslation.php

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

/**
 * CategoryTranslation
 */
class CategoryTranslation
{
    use ORMBehaviors\Translatable\Translation;

    /**
     * @var string
     */
    private $name;

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

        return $this;
    }

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

在奏鸣曲类别管理员中:

$formMapper->add('name', 'a2lix_translations');

当我添加我的类别(访问消息)时,我在数据库中看到" name"看起来像

Doctrine\Common\Collections\ArrayCollection@000000006cb11474000000002980d54f

1 个答案:

答案 0 :(得分:0)

从主类中删除setter和getter,然后doctrine:schema:update。 也在奏鸣曲类别管理员:

$formMapper->add('translations', 'a2lix_translations');