I set up my entities same as https://github.com/KnpLabs/DoctrineBehaviors#translatable . Also configs same as 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. First I get error that $name doesn't exist at 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
.
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
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;
}
}
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
. Also in sonata category admin: