【问题标题】:Knp\DoctrineBehaviors + a2lix_translations + Sonata AdminKnp\DoctrineBehaviors + a2lix_translations + Sonata 管理员
【发布时间】:2014-11-25 21:11:46
【问题描述】:

我将实体设置为与 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。首先,我收到 Category.php 中不存在 $name 的错误。所以我添加它,现在我有错误: Neither the property "name" nor one of the methods "addName()"/"removeName()", "setName()", "name()", "__set()" or "__call()" exist and have public access in class。 问题是他们如何从主要实体中删除设置器/获取器,对我来说这是导致错误的。也许有人对所有这一切都有适当的魔力?

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');

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

Doctrine\Common\Collections\ArrayCollection@000000006cb11474000000002980d54f

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 2016-05-28
      • 2021-07-14
      • 1970-01-01
      相关资源
      最近更新 更多