我想要这样的事情:
<textarea rows="30" cols="70" class="TextBox" style="height:100px;">
但在我的symfony2应用程序中,而不是在twig模板中 我试过这个:
$builder->add('history', 'textarea', array('label' => 'Nome' , 'max_length' => 1048576 , 'rows' = 30 , 'cols' = 70));
但我得到“行”和“cols”不是选项...
在树枝上我想要这样的东西:<label for="history">{{'form_anamnese_history'}}</label>
{{ form_widget(form.history) }}
成为一个像论坛一样的文本框!
答案 0 :(得分:56)
使用attr
数组,如documentation:
$builder->add('history', 'textarea', array(
'attr' => array('cols' => '5', 'rows' => '5'),
));
答案 1 :(得分:7)
您可以在Twig中设置textarea的显示属性,而不是在以下格式中设置:
{{ form_widget(edit_form.comment, { 'attr': {
'style' : 'width:525px',
'rows' : '4',
'cols' : '30' }} ) }}
如上所述,如果可能的话,最好在CSS中设置它。
答案 2 :(得分:1)
Symfony 3
中问题的解决方案。
第一:
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
第二: 这是表单中的代码:
->add('biografia', TextareaType::class, array(
'label' => 'Como me identifico, Identifiquese utilizando un máximo de 500 caracteres',
'attr' => array('class' => 'myclass')
))