[英]Symfony2 FormType : Pass custom options into the fieldType
I would like to pass custom options into my field. 我想将自定义选项传递到我的字段中。 Is there a way to set an array of options into my field "code" ?
有没有办法在我的字段“代码”中设置一个选项数组?
namespace Company\SystemBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ArbitreType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('code','text',array('required' => true))
//->add('code','text',array('required' => true,'customOption'=>array('option1'=>'value1')))
;
}
}
Try : 试试:
$builder
->add('code', 'text', array(
'required' => true,
'attr' => array(
'option1' => 'value1'
)
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.