财产" item"也不是其中一种方法

时间:2015-06-01 14:13:20

标签: forms symfony doctrine entity

我有这个formBuilder。

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('dateStart','genemu_jquerydate',array('required'  => true, 'widget' => 'single_text'))
        ->add('dateFinish','genemu_jquerydate',array('required'  => true, 'widget' => 'single_text'))
        ->add('image', 'genemu_jqueryimage', array(
        'configs' => array(
            'auto' => true,
            'multiple' => false
        )))
        ->add('items', 'genemu_jqueryselect2_entity', array(
            'class' => 'Acme\sampleBundle\Entity\Item',
            'property' => 'name',
            'configs' => array(
                'multiple' => true
                )
            )
        )
        ;
}

当我提交它时会抛出此错误:

  

属性"项目"也不是其中一种方法   " addItem()" /" removeItem()"," setItems()"," items()",&# 34; __集()"要么   " __呼叫()"在课堂上存在并具有公共访问权限   " Acme公司\ sampleBundle \实体\绘图"

<?php

namespace Acme\sampleBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Draw
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="acme\sampleBundle\Entity\DrawRepository")
 */
class Draw
{    
    public function __construct() {
        $this->items = new \Doctrine\Common\Collections\ArrayCollection();
    }

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


    /**
     * @ORM\ManyToMany(targetEntity="Acme\sampleBundle\Entity\Item")
     * @ORM\JoinTable(name="draw_item",
     *      joinColumns={@ORM\JoinColumn(name="draw_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="item_id", referencedColumnName="id")}
     *      )
     * @Assert\NotBlank()
     **/
    private $items;

    /**
     * @ORM\ManyToOne(targetEntity="Acme\sampleBundle\Entity\User", inversedBy="drawsWins")
     * @ORM\JoinColumn(name="user_winner_id", referencedColumnName="id")
     **/
    private $winner;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="dateStart", type="datetime")
     * @Assert\NotBlank()
     */
    private $dateStart;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="dateFinish", type="datetime")
     * @Assert\NotBlank()
     */
    private $dateFinish;

    /**
     * @var string
     *
     * @ORM\Column(name="image", type="text")
     **/
    private $image;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text")
     */
    private $description = '';

    /**
     * @var string
     *
     * @ORM\Column(name="state", type="string", length=1)
     */
    private $state = 0;

    /**
     * @ORM\ManyToOne(targetEntity="Acme\sampleBundle\Entity\User")
     * @ORM\JoinColumn(name="user_maker_id", referencedColumnName="id")
     **/
    private $maker;


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

    /**
     * Set dateStart
     *
     * @param \DateTime $dateStart
     *
     * @return Draw
     */
    public function setDateStart($dateStart)
    {
        $this->dateStart = $dateStart;

        return $this;
    }

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

    /**
     * Set dateFinish
     *
     * @param \DateTime $dateFinish
     *
     * @return Draw
     */
    public function setDateFinish($dateFinish)
    {
        $this->dateFinish = $dateFinish;

        return $this;
    }

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

    /**
     * Set image
     *
     * @param string $image
     *
     * @return Draw
     */
    public function setImage($image)
    {
        $this->image = $image;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set state
     *
     * @param string $state
     *
     * @return Draw
     */
    public function setState($state)
    {
        $this->state = $state;

        return $this;
    }

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

    /**
     * Add item
     *
     * @param \Acme\sampleBundle\Entity\Item $item
     *
     * @return Draw
     */
    public function addItem(\Acme\sampleBundle\Entity\Item $item)
    {
        $this->items[] = $item;

        return $this;
    }

    /**
     * Remove item
     *
     * @param \Acme\sampleBundle\Entity\Item $item
     */
    public function removeItem(\Acme\sampleBundle\Entity\Item $item)
    {
        $this->items->removeElement($item);
    }

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

    /**
     * Set winner
     *
     * @param \Acme\sampleBundle\Entity\User $winner
     *
     * @return Draw
     */
    public function setWinner(\Acme\sampleBundle\Entity\User $winner = null)
    {
        $this->winner = $winner;

        return $this;
    }

    /**
     * Get winner
     *
     * @return \Acme\sampleBundle\Entity\User
     */
    public function getWinner()
    {
        return $this->winner;
    }

    /**
     * Set maker
     *
     * @param \Acme\sampleBundle\Entity\User $maker
     *
     * @return Draw
     */
    public function setMaker(\Acme\sampleBundle\Entity\User $maker = null)
    {
        $this->maker = $maker;

        return $this;
    }

    /**
     * Get maker
     *
     * @return \Acme\sampleBundle\Entity\User
     */
    public function getMaker()
    {
        return $this->maker;
    }
}

有什么建议吗?

解决。只需在数组中添加多个就可以了。

        ->add('items', 'genemu_jqueryselect2_entity', array(
            'class' => 'Acme\sampleBundle\Entity\Item',
            'property' => 'name',
            'multiple' => true,
            'configs' => array(
                'multiple' => true
                )
            )
        )

0 个答案:

没有答案