2016-10-13 4 views
0
...  $form = $this->createFormBuilder($foo) 
     ->add('deviceId', EntityType::class, array(
      'class' => 'FooBundle:Foo', 
      'choice_label' => 'deviceId' 
     )) 
... 

사용자가 deviceId의 어떤 옵션을 찾았는지 어떻게 알 수 있습니까?Symfony 엔티티 유형 - 선택한 값을 얻는 방법

... 
if ($form->isSubmitted() && $form->isValid()) { 
/*Getting the value that was selected 
and doing something with it 
for exampe removing it from the database*/ 
} 
... 

답변

0

나는 양식을 submited 된 경우 이전에 확인하는 것이 생각이 유효한 경우 당신이 할 수 있습니다 :이 경우

$form->handleRequest($request); 

을 개체가

업데이트 되었기 때문에 직접 액세스 할 수 있습니다

$form->getData(); 
:
$yourObject->getDeviceId() 

은 또한이 같은 데이터를 형성하기 위해 액세스 할 수 있습니다

+1

'$ form [ 'deviceId'] -> getData();'는 내가 찾던 것입니다. @DOZ 도움에 감사드립니다. –

관련 문제