0

我与 symfony2 合作,当我嵌入两个表单(组中的人)时遇到问题:

属性“PersonEntity”和方法之一“getPersonEntity()”、“isPersonEntity()”、“hasPersonEntity()”、“_ get()”或“ _call()”都不存在并且在类“S118”中具有公共访问权限\ebrahimiBundle\Entity\GroupEntity”。

我的个人实体:

<?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';
    }
}

为什么???

4

1 回答 1

0

您的 GroupEntityType 表单类型正在您的 GroupEntity 实体中寻找“PersonEntity”字段。你有一个 oneToMany PersonEntities 代替。

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

于 2013-10-25T11:59:10.773 回答