问题描述
- > add('esame_'。$ i,EntityType :: class,array(
'label'=> false,
'mapped'=> false,
'class'=>'AppBundle:Nome_esame',
'required'=> true,
'multiple'=> true,
'choice_label'=>'nome',
//'disabled'=>'disabled',
'attr'=> array(
'placeholder'=>'Esami',
'class'=>'max_width esame_row select_esame',
//'class '=>'col-md-12 col-md-offset-0 col-xs-9 col-xs-offset-3',
)
))
在我的表单提交中,我想获取所有选定的值并从每个值中创建一个新的实体。
我试过这个:
$ $ $ $ $ $ $ $ foreach($ form-> get('esame_0') - > getData )作为$ value){
$ field = new Field();
$ field-> setvalue($ value); // - > $ value我想要的是所选选项的值
}
但是 $ form-> get('esame_0') - > getData()
不会返回选定的数据..
EntityType附带的值是一个Entity对象。试试这种方法。
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ data = $ entityObject-> getId()或$ entityObject->(Entity getter function)
Entity Type is defined as follow in my form:
->add('esame_' . $i, EntityType::class, array(
'label' => false,
'mapped' => false,
'class' => 'AppBundle:Nome_esame',
'required' => true,
'multiple' => true,
'choice_label' => 'nome',
// 'disabled' => 'disabled',
'attr' => array(
'placeholder' => 'Esami',
'class' => 'max_width esame_row select_esame',
// 'class'=>'col-md-12 col-md-offset-0 col-xs-9 col-xs-offset-3 ',
)
))
In my form submit, I want to take all the selected value and create a new entity from every one.I tried this:
foreach($form->get('esame_0')->getData() as $value){
$field= new Field();
$field->setvalue($value); // ->$value i want is the val of selected option
}
but $form->get('esame_0')->getData()
does not return the selected data..
How can I do it?
The value that comes with EntityType is an Entity object. Try this way.
$entityObject = $form->get('esame_0')->getData()
$data = $entityObject->getId() or $entityObject->(Entity getter function)
这篇关于symfony如何从select中获取选定的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!