Symfony2 setSelected实体类型的值

时间:2016-02-23 14:30:15

标签: php symfony symfony-forms

这可能就像一个愚蠢的问题,但我被困住了。我以Symfony2应用程序的形式提供以下字段:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('match_team1','entity', array(
            'class'     => 'MyAppBundle:Team',
            'expanded'  => false,
            'multiple'  => false,
            'label'     => 'Team 1',
            'mapped'    => true,
            'property'  => 'name'

        ));
}

匹配班级

class Match
{


/**
 * @var integer
 */
private $id;


/**
 * @var integer
 */
private $match_number;

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

/**
 * @var \DateTime
 */
private $match_date;

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

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

 /**
 * Set matchTeam1
 *
 * @param string $matchTeam1
 *
 * @return Match
 */
public function setMatchTeam1($matchTeam1)
{
    $this->match_team1 = $matchTeam1;

    return $this;
}

/**
 * Get matchTeam1
 *
 * @return string
 */
public function getMatchTeam1()
{
    return $this->match_team1;
}

编辑功能:

private function createEditForm(Match $entity)
{
    $form = $this->createForm(new MatchType(), $entity, array(
        'action' => $this->generateUrl('match_update', array('id' =>     $entity->getId())),
        'method' => 'PUT',
    ));


    $form->add('submit', 'submit', array('label' => 'Update'));

    return $form;
}

但是当我更新表单时,下拉列表中的选定值不会保留。在数据库中,我可以看到条目,但在表单中它没有显示。任何人都可以帮我设置所选的值吗?

0 个答案:

没有答案