我有一个带有多个复选框列表的表单(选择列表是动态准备的)。我希望从一开始就选择它们(以便用户可以取消选中它们)。我已经准备了一个带有选项和检查选项的数组,但是在表单渲染期间,只选择了第一个复选框。关于如何修复它的任何建议?
$choices = array();
$choices_check= array();
foreach($user[0]->getShops() as $shop)
{
$choices[$shop->getId()] = $shop->getName();
$choices_check[] = true;
}
//return $this->render('GLPolicyBundle:Policy:tmp.html.twig', array('entities' => var_dump($choices_p)));
$searchby = array();
$form = $this->createFormBuilder($searchby)
->add('shop', 'choice', array('choices' => $choices,
'multiple' => true,
'expanded' => true,
'required' => true,
'data' => $choices_check)
)
->add('date_from', 'date', array('data' => $date_from))
->add('date_to', 'date', array('data' => new \DateTime()))
->getForm();