可翻译学说实体的Symfony形式

时间:2013-01-02 15:39:30

标签: php symfony doctrine symfony-forms

我有一个使用Translatable Doctrine extension翻译过的Doctrine实体:

<?php
namespace Myapp\ProductBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;

/**
 * @ORM\Table(name="product_property")
 * @ORM\Entity()
 * @Gedmo\TranslationEntity()
 */
class Property implements Translatable
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @Gedmo\Translatable
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @ORM\OneToMany(
     *   targetEntity="PropertyTranslation",
     *   mappedBy="object",
     *   cascade={"persist", "remove"}
     * )
     */
    private $translations;

    /**
     * @Gedmo\Locale
     * Used locale to override Translation listener`s locale
     * this is not a mapped field of entity metadata, just a simple property
     */
    private $locale;


    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }

    public function getTranslations()
    {
        return $this->translations;
    }

    public function addTranslation(PropertyTranslation $t)
    {
        if (!$this->translations->contains($t)) {
            $this->translations[] = $t;
            $t->setObject($this);
        }
    }
}

现在,我想在我的翻译中为每种语言中的“name”属性的输入字段呈现一个表单。

最好的方法是什么?

1 个答案:

答案 0 :(得分:4)

似乎以下捆绑包能够完全按照我的要求进行操作:https://github.com/a2lix/TranslationFormBundle

enter image description here