0

我正在做一个表格,以便押注比赛的获胜者。形式是经典的:匹配 - 复选框(1、X 或 2)

我可以在创建新赌注时制作表格,但我无法通过预先选择的复选框来编辑赌注。

我的控制器:

public function parierAction()
{

    $matchs = $this->getDoctrine()->getRepository('ParisParisBundle:Matchs')->findAll();
    $user = $this->getUser();

    foreach ($matchs as $match) {

            $pari = new Pari();
            $pari->setMatchs($match);
            $pari->setUser($user);
            $pari->setPari1X2(1);

        $pariss[] = $pari;
    }
    $paris = array ('paris'=>$pariss);

    $form = $this->createForm(new ParisType, $paris);

我的类型

class ParisType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('paris', 'collection', array(
            'type'   => new PariType()));

}

public function getName()
{
    return 'paris_parisbundle_paristype';
}

和 PariType,包含带有复选框的选项

class PariType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('pari1X2', 'choice', array(
            'choices'   => array('1' => '1', '3' => 'X', '2' => '2'),
            'required' => false,
            'expanded'  => true,
            'multiple' => true,


        ));

}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'Paris\ParisBundle\Entity\Pari',

    ));
}

public function getName()
{
    return 'paris_parisbundle_paritype';
}

我使这个例子尽可能简单。如果我删除

$pari->setPari1X2(1);

我会看到复选框。pari1X2 属性是一个小整数。但如果我让它这样,我得到了错误:

Expected an array.

我想整数和选择有冲突,但我无法解决。

编辑:实体类 Pari { /** * @ORM\ManyToOne(targetEntity="Paris\UserBundle\Entity\User") * @ORM\JoinColumn(nullable=false) */ private $user;

/**
 * @ORM\ManyToOne(targetEntity="Paris\ParisBundle\Entity\Matchs")
 * @ORM\JoinColumn(nullable=false)
 */
private $matchs;

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

/**
 * @var \DateTime
 *
 * @ORM\Column(name="datePari", type="date")
 */
private $datePari;

/**
 * @var integer
 *
 * @ORM\Column(name="pari1X2", type="smallint")
 */
private $pari1X2;


class Matchs
{
/**
 * @ORM\ManyToOne(targetEntity="Paris\ParisBundle\Entity\League")
 * @ORM\JoinColumn(nullable=false)
 */
private $league;

/**
 * @ORM\ManyToOne(targetEntity="Paris\ParisBundle\Entity\Team")
 * @ORM\JoinColumn(nullable=false)
 */
private $teamlocal;

/**
 * @ORM\ManyToOne(targetEntity="Paris\ParisBundle\Entity\Team")
 * @ORM\JoinColumn(nullable=false)
 */
private $teamaway;


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

0 回答 0