Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms Symfony2表单-如何将数据从integer属性传递到复选框_Forms_Symfony - Fatal编程技术网

Forms Symfony2表单-如何将数据从integer属性传递到复选框

Forms Symfony2表单-如何将数据从integer属性传递到复选框,forms,symfony,Forms,Symfony,我正在做一张表格,以便赌一场比赛的获胜者。 表单是经典的:匹配复选框(1、X或2) 我可以在创建新赌注时创建表单,但无法使用预选复选框编辑赌注 我的控制器: public function parierAction() { $matchs = $this->getDoctrine()->getRepository('ParisParisBundle:Matchs')->findAll(); $user = $this->getUser(); f

我正在做一张表格,以便赌一场比赛的获胜者。 表单是经典的:匹配复选框(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.
我猜整数和选择之间存在冲突,但我无法解决它

编辑:实体 同等阶级 { /** *@ORM\manytone(targetEntity=“Paris\UserBundle\Entity\User”) *@ORM\JoinColumn(nullable=false) */ 私人用户

/**
 * @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;

听起来你需要一个数据转换器。查看文档并发回你的发现:)我们需要看看你的Paris&Matchs实体