Php Symfony2表单生成器,多选项,例外数组也在示例代码中

Php Symfony2表单生成器,多选项,例外数组也在示例代码中,php,arrays,symfony,Php,Arrays,Symfony,在这个论坛上搜索了几个小时后,谷歌没有给出任何答案。 我尝试了更多类型的数组,比如数组的数组和简单的key=>value数组 我还尝试了以下代码:expanded true和multiple true at 当我打开“multiple”时,出现错误“Expected a array.500 Internal Server error-TransformationFailedException”,我已经用数组数组和密钥对数组进行了尝试 我想要的是做什么和它在做什么 我从数据库中选择视频 转换 $v

在这个论坛上搜索了几个小时后,谷歌没有给出任何答案。 我尝试了更多类型的数组,比如数组的数组和简单的key=>value数组

我还尝试了以下代码:expanded true和multiple true at

当我打开“multiple”时,出现错误“Expected a array.500 Internal Server error-TransformationFailedException”,我已经用数组数组和密钥对数组进行了尝试

我想要的是做什么和它在做什么

  • 我从数据库中选择视频
  • 转换

    $video = $this->entityManager->getRepository("CMMSHomeBundle:Video")->findAll();
    
    if (!$video)
    {
        return '0';
    }
    
    $video_arr = array();
    
    for ($i = 0; $i < count($video); $i++)
    {
        //$video_arr[$i]["id"] = $video[$i]->getId();
        //$video_arr[$i]["videoid"] = $video[$i]->getVideoid();
        $video_arr[$video[$i]->getId()] = $video[$i]->getVideoid();
    }
    return $video_arr;
    
  • $form已链接,我通过这个soverflow编辑器将其解锁以获得正确的格式

    它不起作用:-(只要我打开multiple


    谢谢

    为什么不改用实体表单类型呢?谢谢,我把它改成了实体样式
    $form = $this->createFormBuilder($product);
    $form->add('name', 'text');
    $form->add('short', 'textarea');
    $form->add("description", "textarea");
    $form->add("price", "text");
    $form->add("images", "text");
    $form->add('videos', 'choice', array(
        'choices' => $videos,
        'expanded' => true,
        'multiple' => true,
            )
    );
    $form->add("files", "text");
    $form->add("size", "text");
    $form->add("weight", "text");
    $form->add("category", "text");
    $form->add("active", "text");
    $form->add('save', 'submit');
    $form->getForm();