在表单中为实体添加2种语言的字段

时间:2015-03-02 13:25:33

标签: php entity-framework symfony entity locale

我有一个带有字段的实体页面:

pagelocaleid(PK),说明,内容,区域设置,已翻译和pageid(FK)。

我的实体:

<?php

namespace DX\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
 * Pagelocale
 *
 * @ORM\Table(name="pageLocale", indexes={@ORM\Index(name="fk_pageLocale_page1_idx", columns={"pageID"})})
 * @ORM\Entity(repositoryClass="DX\MyBundle\Repository\PagelocaleRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Pagelocale
{
    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text", length=65535, nullable=true)
     */
    private $description;

    /**
     * @var string
     */
    private $descriptionEN;

    /**
     * @var string
     *
     * @ORM\Column(name="content", type="text", length=65535, nullable=true)
     */
    private $content;

    /**
     * @var string
     */
    private $contentEN;

    /**
     * @var string
     *
     * @ORM\Column(name="locale", type="string", length=5, nullable=true)
     */
    private $locale;

    /**
     * @var boolean
     *
     * @ORM\Column(name="translated", type="boolean", nullable=true)
     */
    private $translated;

    /**
     * @var integer
     *
     * @ORM\Column(name="pageLocaleID", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $pagelocaleid;

    /**
     * @var \DX\MyBundle\Entity\Page
     *
     * @ORM\ManyToOne(targetEntity="DX\MyBundle\Entity\Page")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="pageID", referencedColumnName="pageID")
     * })
     */
    private $pageid;

    /**
     * @var string
     */
    private $tag;

    /**
     * Set tag
     *
     * @param string $tag
     * @return Articlelocale
     */
    public function setTag($tag)
    {
        if($this->pageid)
        {
            $this->pageid->setTag($tag);
        }
        else
        {
            $this->tag = $tag;
        }

        return $this;
    }

    /**
     * Get tag
     *
     * @return string
     */
    public function getTag()
    {
        if($this->pageid)
        {
            return $this->pageid->getTag();
        }
        else
        {
            return $this->tag;
        }
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Pagelocale
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set descriptionEN
     *
     * @param string $descriptionEN
     * @return Pagelocale
     */
    public function setDescriptionEN($descriptionEN)
    {
        $this->descriptionEN = $descriptionEN;

        return $this;
    }

    /**
     * Get descriptionEN
     *
     * @return string
     */
    public function getDescriptionEN()
    {
        return $this->descriptionEN;
    }

    /**
     * Set content
     *
     * @param string $content
     * @return Pagelocale
     */
    public function setContent($content)
    {
        $this->content = $content;

        return $this;
    }

    /**
     * Get content
     *
     * @return string 
     */
    public function getContent()
    {
        return $this->content;
    }


    /**
     * Set contentEN
     *
     * @param string $contentEN
     * @return Pagelocale
     */
    public function setContentEN($contentEN)
    {
        $this->contentEN = $contentEN;

        return $this;
    }

    /**
     * Get contentEN
     *
     * @return string
     */
    public function getContentEN()
    {
        return $this->contentEN;
    }

    /**
     * Set locale
     *
     * @param string $locale
     * @return Pagelocale
     */
    public function setLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }

    /**
     * Get locale
     *
     * @return string 
     */
    public function getLocale()
    {
        return $this->locale;
    }

    /**
     * Set translated
     *
     * @param boolean $translated
     * @return Pagelocale
     */
    public function setTranslated($translated)
    {
        $this->translated = $translated;

        return $this;
    }

    /**
     * Get translated
     *
     * @return boolean 
     */
    public function getTranslated()
    {
        return $this->translated;
    }

    /**
     * Get pagelocaleid
     *
     * @return integer 
     */
    public function getPagelocaleid()
    {
        return $this->pagelocaleid;
    }

    /**
     * Set pageid
     *
     * @param \DX\MyBundle\Entity\Page $pageid
     * @return Pagelocale
     */
    public function setPageid(\DX\MyBundle\Entity\Page $pageid = null)
    {
        $this->pageid = $pageid;

        return $this;
    }
}

我正在使用Sonata Admin Bundle,但在这种情况下这并不重要。

正如您在我的实体中看到的,我手动添加了 contentEN descriptionEN ,因为我想要内容&amp; 2种语言的描述

我希望能够以一种形式而不是两步(为每种语言内容创建)来做到这一点。

现在我的形式是:

$formMapper
    ->add('tag', 'text', array('label' => 'Tag'))
    ->add('description', 'text', array('label' => 'Beschrijving'))
    ->add('descriptionEN', 'text', array('label' => 'Beschrijving Engels'))
    ->add('content', 'textarea', array('label' => 'Tekst', 'attr' => array('class' => 'ckeditor'), 'help' =>
        'My help text.'))
    ->add('contentEN', 'textarea', array('label' => 'Tekst Engels', 'attr' => array('class' => 'ckeditor'), 'help' =>
        'My help text.'))
;

我可以创建2个不同的实体并设置区域设置,这没问题。但是当我想编辑它们时, contentEN &amp;逻辑上没有填写 descriptionEN 。如何确保我获得描述和内容 where locale = ..

更新:
我的数据库结构:

enter image description here

所以我没有桌面,语言环境和pagelocale。

0 个答案:

没有答案