我想创建Pracownik
可以包含零个或几个实例的表,Zaklady
并使用 Sonata Admin 控制它。这两个表都使用 a2lix_translatable 进行翻译。
所以我有课:
<?php
namespace JCuryllo\InstituteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* Pracownik
*
* @ORM\Table()
* @ORM\Entity
*/
class Pracownik
{
use ORMBehaviors\Translatable\Translatable;
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
/**
* @ORM\ManyToOne(targetEntity="ZakladyTranslation")
**/
private $zaklady;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* and other properties
*/
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/* and other getters and setter */
}
和翻译:
<?php
namespace JCuryllo\InstituteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Entity
*/
class PracownikTranslation
{
use ORMBehaviors\Translatable\Translation;
public function __toString()
{
return $this->getTitle();
}
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/* and other properties */
/**
* Set name
*
* @param string $name
* @return Pracownik
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/* and other getters and setter *.
}
我在Zaklady
and中使用了非常相似的代码ZakladyTranslation
。然后在PracownikAdmin
我尝试做某事:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('zaklady', 'many_to_one',array(
'required' => false,
))
->add('translations', 'a2lix_translations')
;
}
但它不起作用(错误:无法加载类型“many_to_one”)。