我将我的实体设置为与https://github.com/KnpLabs/DoctrineBehaviors#translatable相同。配置也与http://a2lix.fr/bundles/translation-form/相同。我还添加了 __call 方法并尝试使用来自 kpnlabs 的 DoctrineBehaviors 在奏鸣曲管理员中打印可翻译数据。首先,我收到 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
。问题是他们如何从主要实体中删除设置器/获取器,对我来说这是导致错误的。也许有人对所有这一切都有适当的魔力?
分类.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
#}
// ...
类别翻译.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