symfony2 controllerからのformTypeの操作
choice生成用の配列の受け渡しとselectedの設定
controller側
$data = array( '1'=> 'a', '2'=>'b'); $form = $this->createForm( new hogeType(), $data ); //selectedの設定。例はbの項目がselectedになる $form->get('foo')->setData('2');
hogeType
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('foo', 'choice', array('choices'=>$options['data'])); }
というようにcontrollerから渡された配列は$options['data']で参照出来る。