2012-10-31 75 views
3

我有一個表格,並需要在bindrequest字段類型項目類型,方法GetType不要工作得很好:Symfony2中得到形式

$peticion = $this->getRequest(); 
     if ($peticion->getMethod() == 'POST') 
     { 
      $form->bindRequest($peticion); 

      if ($form->isValid()) { 

      foreach($form as $key => $per) 
         $per->getType(); // i want the type of item [text,checkbox,etc] the method getType() dont work 
}} 

回答

9

使用此:

foreach($form as $key => $per) { 
    $per->getConfig()->getType()->getName(); 
} 
+0

謝謝,非常漂亮 –