A2lix TranslationFormBundle - Gedmo Doctrine Extension - 不需要的表单字段

时间:2015-01-31 12:16:45

标签: forms symfony doctrine-orm internationalization translation

我正在尝试为可翻译实体构建表单,但我得到了4个我不想要的表单字段。

看来这些字段来自Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation,但我想知道我需要对这些字段做些什么?

他们出现在翻译表格中是否正常?

enter image description here

如果某人有有用的例子会很棒。

请在下面找到以下文件:

  • Page.php(这是主要实体)
  • PageTranslation.php(翻译实体)

page.php文件

<?php

namespace Syms\PageBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Page
 *
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="syms_page")
 * @ORM\Entity(repositoryClass="Syms\PageBundle\Entity\PageRepository")
 */
class Page
{

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

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_active", type="boolean", nullable=false, options={"default":0})
     */
    private $isActive;

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_homepage", type="boolean", nullable=false, options={"default":0})
     */
    private $isHomepage;

    /**
     * @var \DateTime
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="created_at", type="datetime")
     */
    private $createdAt;

    protected $translations;


    /**
     * @Gedmo\TreeLeft
     * @ORM\Column(name="lft", type="integer")
     */
    private $lft;

    /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rgt;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

    /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $parent;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

    /**
     * @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    private $children;

    /**
     * Required for Translatable behaviour
     * @Gedmo\Locale
     */
    protected $locale;


    /**
     * Constructor
     */
    public function __construct()
    {
        $this->children = new ArrayCollection();
        $this->translations = new ArrayCollection();
    }

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

    /**
     * Set isActive
     *
     * @param boolean $isActive
     * @return Page
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

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

    /**
     * Set isHomepage
     *
     * @param boolean $isHomepage
     * @return Page
     */
    public function setIsHomepage($isHomepage)
    {
        $this->isHomepage = $isHomepage;

        return $this;
    }

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

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Page
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }


    public function setParent(Page $parent)
    {
        $this->parent = $parent;
    }

    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Set lft
     *
     * @param integer $lft
     * @return Page
     */
    public function setLft($lft)
    {
        $this->lft = $lft;

        return $this;
    }

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

    /**
     * Set rgt
     *
     * @param integer $rgt
     * @return Page
     */
    public function setRgt($rgt)
    {
        $this->rgt = $rgt;

        return $this;
    }

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

    /**
     * Set lvl
     *
     * @param integer $lvl
     * @return Page
     */
    public function setLvl($lvl)
    {
        $this->lvl = $lvl;

        return $this;
    }

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

    /**
     * Set root
     *
     * @param integer $root
     * @return Page
     */
    public function setRoot($root)
    {
        $this->root = $root;

        return $this;
    }

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


    /**
     * Add children
     *
     * @param \Syms\PageBundle\Entity\Page $children
     * @return Page
     */
    public function addChild(Page $children)
    {
        $this->children[] = $children;

        return $this;
    }

    /**
     * Remove children
     *
     * @param \Syms\PageBundle\Entity\Page $children
     */
    public function removeChild(Page $children)
    {
        $this->children->removeElement($children);
    }

    /**
     * Get children
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getChildren()
    {
        return $this->children;
    }



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

    public function addTranslation(PageTranslation $t)
    {
        $this->translations->add($t);
        $t->setObject($this);
    }

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

    public function setTranslations($translations)
    {
        $this->translations = $translations;
    }

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

PageTranslation.php

<?php

namespace Syms\PageBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @ORM\Table(name="ext_translations_page", indexes={
*      @ORM\Index(name="page_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class PageTranslation extends AbstractTranslation
{

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

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

    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="meta_keywords", type="text", nullable=true)
     */
    private $metaKeywords;

    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="meta_description", type="text", nullable=true)
     */
    private $metaDescription;

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


    /**
     * Set title
     *
     * @param string $title
     * @return PageTranslation
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

    /**
     * Set metaTitle
     *
     * @param string $metaTitle
     * @return PageTranslation
     */
    public function setMetaTitle($metaTitle)
    {
        $this->metaTitle = $metaTitle;

        return $this;
    }

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

    /**
     * Set metaKeywords
     *
     * @param string $metaKeywords
     * @return PageTranslation
     */
    public function setMetaKeywords($metaKeywords)
    {
        $this->metaKeywords = $metaKeywords;

        return $this;
    }

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

    /**
     * Set metaDescription
     *
     * @param string $metaDescription
     * @return PageTranslation
     */
    public function setMetaDescription($metaDescription)
    {
        $this->metaDescription = $metaDescription;

        return $this;
    }

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

    /**
     * Set urlKey
     *
     * @param string $urlKey
     * @return PageTranslation
     */
    public function setUrlKey($urlKey)
    {
        $this->urlKey = $urlKey;

        return $this;
    }

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

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

}

1 个答案:

答案 0 :(得分:1)

我终于成功地显示了正确的字段。

您必须将a2lix表单包降级到1.4版。

事实上,在2.0版本中,字段类型&#34; a2lix_translations_gedmo&#34;不再可用,这实际上是使用Gedmo Translatable时所需要的。

您的实体方面没有任何改变。只需按照doc获取config.yml,然后使用&#34; a2lix_translations_gedmo&#34;在你的PageType:

     <h4>Please fill out the following form and we will be in touch with you soon.</h4>
<form action="mytest.php" method="post" id="contactform">
  <ol>
    <li>
      <label for="name">Your Name <span class="red">*</span></label>
      <input id="name" name="name" class="text" />
    </li>
    <li>
      <label for="email">Your email <span class="red">*</span></label>
      <input id="email" name="email" class="text" />
    </li>
    <li>
      <label for="subject">Subject</label>
      <input id="subject" name="subject" class="text" />
    </li>
    <li>
      <label for="message">Message <span class="red">*</span></label>
      <textarea id="message" name="message" rows="6" cols="50"></textarea>
    </li>
    <li class="buttons">
      <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
      <div class="clr"></div>
    </li>
  </ol>
</form> 


<?php

if(!$_POST) exit;

$email = $_POST['email'];

$errors=0;

if($errors==1) echo $error;
else{
    $email_from = $_POST['email'];
$email_from = "from@gmail.com";
$headers = "From: " . strip_tags( $_POST['name'] ) . "\r\n";

$mail_to_send_to = "to@gmail.com";
$your_feedbackmail = "from@gmail.com";
$sendflag = 'send';                       
if ( $sendflag == "send" )
        {
                $email = $_REQUEST['email'] ;
                $message = $_REQUEST['message'] ;
                $headers = "From: $your_feedbackmail" . "\r\n" . "Reply-To: $email" . "\r\n" ;
                $a = mail( $mail_to_send_to, "Feedback Form Results", $message, $headers );
                if ($a)
                {
                     print("Message was sent, you can send another one");
                } else {
                     print("Message wasn't sent, please check that you have changed emails in the bottom");
                }
        }
}
?>

我也可以使用版本2.0的a2lix Form Bundle保持红色,但在这种情况下,你必须使用特定的branch学说扩展(wip-v2.4.0)。 / p>

此致