Symfony2在表单中获取项类型

时间:2012-10-31 19:28:50

标签: symfony symfony-2.1

我有一个表单,并且需要bindrequest中的字段类型,方法getType不能正常工作:

$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
 }}

1 个答案:

答案 0 :(得分:10)

使用此:

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