0

我有这个实体:

配置文件.php

/**
 * LoPati\BlogBundle\Entity\Profile
 *
 * @ORM\Table(name="profile")
 * @ORM\Entity
 * @Gedmo\TranslationEntity(class="LoPati\BlogBundle\Entity\ProfileTranslation")
 */
class Profile
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

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

    /**
     * @var text $description
     * @Gedmo\Translatable
     * @ORM\Column(name="description", type="text", nullable=true)
     */
    protected $description=null;

    /**
     * @ORM\OneToMany(targetEntity="ProfileTranslation", 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;
    }

    public function getLocale()
    {
        return $this->locale;
    }

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

    public function setName($name)
    {
        $this->name=$name;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setDescription($description)
    {

    }

    public function getDescription()
    {
        return $this->description;
    }

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

    public function addTranslation(ProfileTranslation $t)
    {

        $this->translations->add($t);
        $t->setObject($this);

        $this->name = $this->translations[0];
        $this->description = $this->translations[1];
    }

    public function removeTranslation(ProfileTranslation $t)
    {
        $this->translations->removeElement($t);
    }

    public function setTranslations($translations)
    {
        $this->translations = $translations;
        $this->name = $this->translations[0];
$this->description = $this->translations[1];
    }

    public function __toString()
    {
        return "hola";
    }

}

和 ProfileTranslation.php

/**
 * @ORM\Entity
 * @ORM\Table(name="profile_translations",
 *     uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
 *         "locale", "object_id", "field"
 *     })}
 * )
 */
class ProfileTranslation 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="Profile", inversedBy="translations")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $object;

    public function __toString()
    {
        return $this->getContent();
    }
}

我希望在编辑作为 ProfileTranslation 表的 arraycollection 时,还更新名称和描述字段,但形成 Profile Table,它是该集合的第一个元素。

它在我创建新配置文件时工作,但是当我编辑此配置文件时,只更新 ProfileTranslation 表而不是 Profile 表。

我该怎么做?

4

1 回答 1

0

您的实现摒弃了一些过于经典的可翻译用途。

如果它适合你,你也许可以看看TranslationFormBundle及其演示。

于 2012-08-21T10:10:01.607 回答