嵌入以形成symfony2

时间:2013-10-25 11:43:33

标签: forms symfony

我使用symfony2并且当我嵌入两个表单(组中的人)时遇到问题:

属性“PersonEntity”和方法之一“getPersonEntity()”,“isPersonEntity()”,“hasPersonEntity()”,“_ get()”或“ _call() “在课堂上存在并具有公共访问权限”S118 \ ebrahimiBundle \ Entity \ GroupEntity“。

我的PersonEntity:

<?php
namespace S118\ebrahimiBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;

/** 
 * @ORM\Entity
 */
class PersonEntity
{
    /** 
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /** 
     * @ORM\Column(type="string", length=100, nullable=false)
     */
    private $f_name;

    /** 
     * @ORM\Column(type="string", length=100, nullable=false)
     */
    private $l_name;

    /** 
     * @ORM\Column(type="string", length=100, nullable=true)
     */
    private $tell;

    /** 
     * @ORM\Column(type="string", length=100, nullable=true)
     */
    private $fileName;

    /** 
     * @ORM\OneToMany(targetEntity="S118\ebrahimiBundle\Entity\BuyEntity", mappedBy="PersonEntity")
     */
    private $BuyEntities;

    /** 
     * @ORM\OneToMany(targetEntity="S118\ebrahimiBundle\Entity\UsageEntity", mappedBy="PersonEntity")
     */
    private $UsageEntities;

    /** 
     * @ORM\ManyToOne(targetEntity="S118\ebrahimiBundle\Entity\GroupEntity", inversedBy="PersonEntities")
     * @ORM\JoinColumn(name="Gid", referencedColumnName="id", nullable=false)
     */
    private $GroupEntity;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->BuyEntities = new \Doctrine\Common\Collections\ArrayCollection();
        $this->UsageEntities = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set f_name
     *
     * @param string $fName
     * @return PersonEntity
     */
    public function setFName($fName)
    {
        $this->f_name = $fName;

        return $this;
    }

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

    /**
     * Set l_name
     *
     * @param string $lName
     * @return PersonEntity
     */
    public function setLName($lName)
    {
        $this->l_name = $lName;

        return $this;
    }

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

    /**
     * Set tell
     *
     * @param string $tell
     * @return PersonEntity
     */
    public function setTell($tell)
    {
        $this->tell = $tell;

        return $this;
    }

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

    /**
     * Set fileName
     *
     * @param string $fileName
     * @return PersonEntity
     */
    public function setFileName($fileName)
    {
        $this->fileName = $fileName;

        return $this;
    }

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

    /**
     * Add BuyEntities
     *
     * @param \S118\ebrahimiBundle\Entity\BuyEntity $buyEntities
     * @return PersonEntity
     */
    public function addBuyEntitie(\S118\ebrahimiBundle\Entity\BuyEntity $buyEntities)
    {
        $this->BuyEntities[] = $buyEntities;

        return $this;
    }

    /**
     * Remove BuyEntities
     *
     * @param \S118\ebrahimiBundle\Entity\BuyEntity $buyEntities
     */
    public function removeBuyEntitie(\S118\ebrahimiBundle\Entity\BuyEntity $buyEntities)
    {
        $this->BuyEntities->removeElement($buyEntities);
    }

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

    /**
     * Add UsageEntities
     *
     * @param \S118\ebrahimiBundle\Entity\UsageEntity $usageEntities
     * @return PersonEntity
     */
    public function addUsageEntitie(\S118\ebrahimiBundle\Entity\UsageEntity $usageEntities)
    {
        $this->UsageEntities[] = $usageEntities;

        return $this;
    }

    /**
     * Remove UsageEntities
     *
     * @param \S118\ebrahimiBundle\Entity\UsageEntity $usageEntities
     */
    public function removeUsageEntitie(\S118\ebrahimiBundle\Entity\UsageEntity $usageEntities)
    {
        $this->UsageEntities->removeElement($usageEntities);
    }

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

    /**
     * Set GroupEntity
     *
     * @param \S118\ebrahimiBundle\Entity\GroupEntity $groupEntity
     * @return PersonEntity
     */
    public function setGroupEntity(\S118\ebrahimiBundle\Entity\GroupEntity $groupEntity)
    {
        $this->GroupEntity = $groupEntity;

        return $this;
    }

    /**
     * Get GroupEntity
     *
     * @return \S118\ebrahimiBundle\Entity\GroupEntity 
     */
    public function getGroupEntity()
    {
        return $this->GroupEntity;
    }
    public function  __toString()
    {
        return $this->f_name.' '.$this->l_name;

    }
}

和我的团体实体:

<?php
namespace S118\ebrahimiBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;

/** 
 * @ORM\Entity
 */
class GroupEntity
{
    /** 
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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

    /** 
     * @ORM\OneToMany(targetEntity="S118\ebrahimiBundle\Entity\BuyEntity", mappedBy="GroupEntity")
     */
    private $BuyEntities;

    /** 
     * @ORM\OneToMany(targetEntity="S118\ebrahimiBundle\Entity\PersonEntity", mappedBy="GroupEntity")
     */
    private $PersonEntities;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->BuyEntities = new \Doctrine\Common\Collections\ArrayCollection();
        $this->PersonEntities = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set name
     *
     * @param string $name
     * @return GroupEntity
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

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

    /**
     * Add BuyEntities
     *
     * @param \S118\ebrahimiBundle\Entity\BuyEntity $buyEntities
     * @return GroupEntity
     */
    public function addBuyEntitie(\S118\ebrahimiBundle\Entity\BuyEntity $buyEntities)
    {
        $this->BuyEntities[] = $buyEntities;

        return $this;
    }

    /**
     * Remove BuyEntities
     *
     * @param \S118\ebrahimiBundle\Entity\BuyEntity $buyEntities
     */
    public function removeBuyEntitie(\S118\ebrahimiBundle\Entity\BuyEntity $buyEntities)
    {
        $this->BuyEntities->removeElement($buyEntities);
    }

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

    /**
     * Add PersonEntities
     *
     * @param \S118\ebrahimiBundle\Entity\PersonEntity $personEntities
     * @return GroupEntity
     */
    public function addPersonEntitie(\S118\ebrahimiBundle\Entity\PersonEntity $personEntities)
    {
        $this->PersonEntities[] = $personEntities;

        return $this;
    }

    /**
     * Remove PersonEntities
     *
     * @param \S118\ebrahimiBundle\Entity\PersonEntity $personEntities
     */
    public function removePersonEntitie(\S118\ebrahimiBundle\Entity\PersonEntity $personEntities)
    {
        $this->PersonEntities->removeElement($personEntities);
    }

    /**
     * Get PersonEntities
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getPersonEntities()
    {
        return $this->PersonEntities;
    }
    public function  __toString()
    {
        return $this->name;

    }
}

和我的小组观点:

{% extends '::base.html.twig' %}

{% block body -%}
    <h1>GroupEntity creation</h1>

    {{ form(form) }}

        <ul class="record_actions">
    <li>
        <a href="{{ path('group') }}">
            Back to the list
        </a>
    </li>
</ul>
{% endblock %}

和我的人形成:

<?php

namespace S118\ebrahimiBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PersonEntityType extends AbstractType
{
        /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('f_name')
            ->add('l_name')
            ->add('tell')
            ->add('fileName')
            ->add('GroupEntity')
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'S118\ebrahimiBundle\Entity\PersonEntity'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 's118_ebrahimibundle_personentity';
    }
}

和我的小组形式:

<?php

namespace S118\ebrahimiBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class GroupEntityType extends AbstractType
{
        /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('PersonEntity','collection', array('type' => new PersonEntityType()))
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'S118\ebrahimiBundle\Entity\GroupEntity'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 's118_ebrahimibundle_groupentity';
    }
}

为什么???

1 个答案:

答案 0 :(得分:0)

您的GroupEntityType表单类型正在寻找一个&#39; PersonEntity&#39; GroupEntity实体中的字段。你有一个OneToMany PersonEntities。

尝试将PersonEntity替换为GroupEntityType中的PersonEntity。

相关问题