您可以使用自定义格式:
<div class="form-group">
{{ form_label(form.your_value, 'Your Title of field', { 'label_attr': {'class': 'col-sm-3 control-label'} }) }}
<div class="col-sm-9">
{{ form_widget(form.your_value, { 'attr': {'class': 'form-control selectJS'} }) }}
</div>
</div>
,或者您可以使用FormType(如果生成的实体,这是表格文件夹文件),喜欢的:
<?php
namespace Ens\YourBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class NoticeType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title','text', array(
'label'=>'Title',
'label_attr'=>array('class'=>'col-sm-3 control-label'),
'attr'=>array('class'=> 'form-control')
))
->add('text', 'textarea', array(
'label'=>'Text',
'label_attr'=>array('class'=>'col-sm-3 control-label'),
'attr'=>array('class'=> 'form-control')
))
->add('keep_on_top','checkbox', array(
'label'=>'Keep on top',
'required'=>false
))
->add('start', 'date', array(
'attr'=>array('class'=> 'hidden')
))
->add('end', 'date', array(
'attr'=>array('class'=> 'hidden')
))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Ens\YourBundle\Entity\Notice'
));
}
/**
* @return string
*/
public function getName()
{
return 'notice';
}
}
有用的答案,帮我发现新的东西。谢谢 – 2015-02-09 00:54:21
看我的编辑,我不知道这是否有帮助。我希望能够使用该类型并按照我的意愿使用它。 – 2015-02-09 09:01:25
您是否尝试覆盖checkbox_label块? – Gildas 2015-02-09 13:17:12