public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('manifestations', 'entity', array(
'class' => 'PrifProtocoleBundle:Manifestation',
'multiple' => true,
'required'=>false
));
}
$manifestations = $form['manifestations']->getData();
$manifestations = $this->getValue('manifestations');
答案 0 :(得分:1)
$manifestations = $form['manifestations']->getData();
对我来说很好。如果在Manifestation类中你有字段$ name,那么你可以使用getName()
方法。像这样:
$manifestations = $form['manifestations']->getData();
$name = $manifestations->getName();
或者你可以使用Request:
$form = $request->request->get('form');
$manifestations = $form['manifestations'];
P.S。:'form
'是表单的名称。
答案 1 :(得分:0)
你可以像这样获取
use Symfony\Component\HttpFoundation\Request;
public function testAction(Request $request){
$data=$request->request->all(); $data['form_name']['manifestations'];
or $data['manifestations'];
return new response(json_encode($data));
}
答案 2 :(得分:0)
Ashot的答案运作良好。 就我而言:
$currency = $form['currency']->getData();
var_dump($currency->getName());
输出:
string(3) "USD"