dongzhi6087 2015-09-30 14:30
浏览 43
已采纳

Symfony 2 - 在所有视图中包含表单并由一个控制器处理

I am using Symfony 2 and having a little issue with an embeded form.

The situation :

MyBundle/Resources/views/Portions/footer.html.twig view which is included in the MyBundle/Resources/views/layout, and of course the layout.twig.html is extended by all the bundle views. Whish means that footer.html.twig is displayed in all the pages.

The question / problem :

I want to embed a newsletter form (one input) in the footer.html.twig, that would be handled by one controller (validate data, database insert, and email send), and afterward, returning to the same page.

What is the optimized solution to handle this ?

Thank you.

  • 写回答

1条回答 默认 最新

  • duanqiao1880 2015-10-02 09:42
    关注

    an easy way of doing this (not the best way)

    Is to simple define a service, as a twig global, that way you can have your form available, to twig, all the time.

    # Twig Configuration
    twig:
        ...
        globals:
            myGlobaService: "@acme.newsletter_service"
    

    Another simple way of doing this, is to just use the twig render tag, to include the entire controller action, wich renders the template.

    {{ render(controller('AcmeNewsLetterBundle:Default:renderNewsletterForm', {})) }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码