Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

symfony - How to render a checkbox that is checked by default with the symfony2 Form Builder?

I have not found any easy way to accomplish to simply check a Checkbox by default. That can not be that hard, so what am i missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can also just set the attr attribute in the form builder buildForm method:

$builder->add('isPublic', CheckboxType::class, array(
    'attr' => array('checked'   => 'checked'),
));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...