How can I make a custom field type in symfony2?

后端 未结 3 1483
悲&欢浪女
悲&欢浪女 2020-12-08 15:48

I want to make a custom form field in symfony2 named daterange, which will extends the default symfony date type form field and take date range(start date and e

3条回答
  •  我在风中等你
    2020-12-08 16:40

    In order to do that, you need to add the following lines into app/config/config.yml

    twig:
        form:
            resources:
                - 'YourSuperBundle:Form:fields.html.twig'
    

    then in src/Your/SuperBundle/Resources/views/Form/fields.html.twig:

    {% extends 'form_div_layout.html.twig' %}
    
    {% block daterange_widget %}
         ... do the customization.
    {% endblock %}
    

    For additional reference please read form customization of Symfony 2.0 book.

提交回复
热议问题