loops - Symfony2 Looping Same field in form -
i have problem in symfony2 form. have same field in form. create 1 one changing name.
$formbuilderupload = $this->createformbuilder()->setaction($this->generateurl('bsi_bkpm_backend_uploadfile_create')); $formbuilder = $formbuilderupload; $formbuilder->add('file_1','file', array('required'=> false, 'label'=> 'file 1')) ->add('filename_1' , 'text', array( 'required' => false, 'label' => 'subject 1' )) ->add('description_1','text',array('required'=> false, 'label'=>' description 1')) ->add('file_2','file', array('required'=> false, 'label'=> 'file 2')) ->add('filename_2' , 'text', array( 'required' => false, 'label' => 'subject 2')) ->add('description_2','text',array('required'=> false, 'label'=>' description 2')) ->add('file_3','file', array('required'=> false, 'label'=> 'file 2')) ->add('filename_3' , 'text', array( 'required' => false, 'label' => 'subject 3')) ->add('description_3','text',array('required'=> false, 'label'=>' description 4')) ->add('file_4','file', array('required'=> false, 'label'=> 'file 2')) ->add('filename_4' , 'text', array( 'required' => false, 'label' => 'subject 4')) ->add('description_4','text',array('required'=> false, 'label'=>' description 4')) ->add('file_5','file', array('required'=> false, 'label'=> 'file 5')) ->add('filename_5' , 'text', array( 'required' => false, 'label' => 'subject 5')) ->add('description_5','text',array('required'=> false, 'label'=>' description 5')) // add submit button ->add('submit', 'submit', array('label' => 'create')); //create form $form = $formbuilder->getform(); return $form;
but want code become efficient looping it. know how looping it?
best regards,
hendrawan
this seems pretty easy one, loop on loop so...
$limit = 5; ($i = 1; $i <= $limit; $i++) { $builder ->add('file_'.$i, 'file', array( 'required' => false, 'label' => 'file '.$i, )) ->add('filename_'.$i, 'text', array( 'required' => false, 'label' => 'subject '.$i, )) ->add('description_'.$i, 'text', array( 'required' => false, 'label' => 'description '.$i, )) ; }
Comments
Post a Comment