1
class ProfilesSearchType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('disabilityType', 'entity', array(
'class' => 'AldenXyzBundle:DisabilityType',
'property' => 'name',
'multiple' => true,
'expanded' => true,
))
;
}
类的表单称为控制器
public function listAction()
{
$form = $this->createForm(
new \Alden\XyzBundle\Form\Type\ProfilesSearchType(), array());
if (isset($_GET['profile_search']))
{
$form->bindRequest($request);
$d = $form->getData();
// some stuff here
}
return array(
'form' => $form->createView()
);
}
如何从disabilityType设置所有复选框默认为选中? 类定义是(我删除getter和setter方法)
class DisabilityType {
/**
* @var integer $disabilityTypeId
*
* @ORM\Column(name="disability_type_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $disabilityTypeId;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name;
/**
* @var Profile
*
* @ORM\ManyToMany(targetEntity="Profile", mappedBy="disabilityType")
*/
private $profile;
public function __construct()
{
$this->profile = new \Doctrine\Common\Collections\ArrayCollection();
}
}
这不是很好的解决方案,因为我使用的表单没有类,如开头所述。 – koral