twig 模板引擎的 form_widget
我目前正在更新一个 PHP 应用程序,以便它使用非常好的 twig 模板引擎。
我在如何解决这个问题上遇到了障碍。该应用程序有自己的一组定制开发的表单类。本质上,我们可以通过编程方式向表单对象添加字段、设置方法和操作。完成这一切后,将调用 render()
方法,然后该方法会为表单生成生成的 HTML 片段。
我能够使用 raw
过滤器在模板中输出表单,如下所示:
{{ form|raw }}
虽然这效果很好,但我注意到 symfony2 有一个名为 form_widget() 专门处理渲染表单,而不必输出为原始数据。
我想调整该应用程序,以便可以使用 form_widget()
,但是,我无法找到任何有关它的深入文档。谁能指出如何在不使用 symphony2 框架的情况下将数据传递到 form_widget()
?是数组、对象还是其他什么?
I am currently updating a PHP application so that it uses the very nice twig template engine.
I have hit a snag as to how to approach this issue. The application has their own set of custom developed form classes. Essentially, one can progammatically add fields, set methods and actions to the form object. Once this is all done, a the render()
method is called, which then spits out a generated HTML snippet for the form.
I was able to output the form in a template using the raw
filter like so:
{{ form|raw }}
While this works well, I notice that symfony2 has a method called form_widget() which specifically deals with rendering forms without having to output as raw.
I would like to adapt the application so that I can use form_widget()
, however, I am unable to find any indepth documentation on it. Can anyone point out how data should be passed to form_widget()
without using the symphony2 framework? Whether it is an array, object, or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在查看了 Symphony 的源代码后,看起来他们所做的只是创建了一个扩展,以便将表单呈现为 HTML:
所以,我想我需要做的就是创建我自己的 twig 扩展来提供类似的功能。
After looking at the trawling through Symphony's source code, it looks like all they have done is created an extension so that forms will be rendered as HTML:
So, I guess all I need to do is create my own twig extension to provide similiar functionality.