[英]Knp\DoctrineBehaviors + a2lix_translations + Sonata Admin
I set up my entities same as https://github.com/KnpLabs/DoctrineBehaviors#translatable . 我将实体设置为与https://github.com/KnpLabs/DoctrineBehaviors#translatable相同。 Also configs same as http://a2lix.fr/bundles/translation-form/ .
也与http://a2lix.fr/bundles/translation-form/配置相同。 Also I add __call method and try to implement How to print translatable data in sonata admin with DoctrineBehaviors from kpnlabs .
另外,我添加了__call方法,并尝试使用kpnlabs中的DoctrineBehaviors在Sonata admin中实现如何打印可翻译数据 。 First I get error that $name doesn't exist at Category.php.
首先,我得到一个错误,即$ name在Category.php中不存在。 So I add it, now I have error:
Neither the property "name" nor one of the methods "addName()"/"removeName()", "setName()", "name()", "__set()" or "__call()" exist and have public access in class
. 所以我添加了它,现在出现了错误:
Neither the property "name" nor one of the methods "addName()"/"removeName()", "setName()", "name()", "__set()" or "__call()" exist and have public access in class
。 Question is how they remove setters/getters from main Entity, for me it's caused errors. 问题是他们如何从主要实体中删除设置者/获取者,对我来说这是导致错误的原因。 Maybe someone have proper magic for all of this?
也许有人对此具有适当的魔力?
Category.php 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 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;
}
}
In sonata category admin: 在奏鸣曲类别管理员中:
$formMapper->add('name', 'a2lix_translations');
When I added my category(access message) I see in database "name" looks like 当我添加类别(访问消息)时,我在数据库中看到的“名称”看起来像
Doctrine\Common\Collections\ArrayCollection@000000006cb11474000000002980d54f
Remove setters and getters from main class then doctrine:schema:update
. 从主类中删除设置器和获取器,然后删除
doctrine:schema:update
。 Also in sonata category admin: 另外在奏鸣曲类别管理员:
$formMapper->add('translations', 'a2lix_translations');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.