我在Symfony的2.5與a2lix_translations和Gedmo教義的擴展Symfony2的翻譯形式
- gedmo /教義的擴展工作 「: 」DEV-主
- a2lix /翻譯形式束「:」 2。 * @ dev
我正在嘗試在實體集合中添加一個帶有值名稱和說明的翻譯。
這裏是我的實體集:
/**
* Collection
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Angeli\AdminBundle\Entity\CollectionRepository")
* @Gedmo\TranslationEntity(class="Angeli\AdminBundle\Entity\CollectionTranslation")
*/
class Collection
{
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="description", type="text")
*/
private $description;
/**
* @ORM\OneToMany(targetEntity="CollectionTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
protected $translations;
/**
* Required for Translatable behaviour
* @Gedmo\Locale
*/
protected $locale;
public function __construct()
{
$this->translations = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Collection
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
* @return Collection
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(CollectionTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(CollectionTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
$this->translations = $translations;
}
public function __toString()
{
return $this->getName();
}
}
這裏是我的CollectionTranslation類:
/**
* @ORM\Entity
* @ORM\Table(name="collection_translations",
* uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
* "locale", "object_id", "field"
* })}
*)
*/
class CollectionTranslation extends AbstractPersonalTranslation
{
/**
* Convinient constructor
*
* @param string $locale
* @param string $field
* @param string $content
*/
public function __construct($locale = null, $field = null, $content = null)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($content);
}
/**
* @ORM\ManyToOne(targetEntity="Collection", inversedBy="translations")
* @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $object;
}
現在我正在努力建設一個形式:
class CollectionType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
//$builder->add('name','text', array('required' => true, 'label'=>'Name'));
//$builder->add('description','textarea', array('required' => true, 'label'=>'Description'));
$builder->add('translations', 'a2lix_translations');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Angeli\AdminBundle\Entity\Collection',
));
}
public function getName()
{
return 'Collection';
}
}
不過我的表格存在3種語言標籤 和輸入字段
- 場
- 內容
如果我添加
- 場=名稱
- 內容=一些文字
我只翻譯了值 「名」
我想要一個帶有我的語言選項卡和「名稱」和「描述」的表單作爲翻譯表單中的輸入字段。
有人看到我在做什麼錯了?