Symfony - 更改嵌入式表单的模板
我制作了一个表单,其中嵌入表单以使用ajax以一对多关系添加新记录,我的问题是,在哪里编辑嵌入表单的模板?因为我假设这将在 _form.php 中,但它似乎没有使用该模板
提前致谢
I have made a form which embedded forms to add new records in a one-to-many relationship with ajax, my question is, where do I edit the template for the embedded form? because I would assume this would be in _form.php but it doesn't seem to use that template
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您通过 ajax 添加字段,您可以使用一些模板来执行 ajax 的响应。例如,如果您有一个邮件字段,您可以执行以下操作:
并制作一个 _addMail 模板:
这样您就可以使用模板进行 ajax 响应。
If your are adding fields by ajax you can do the response of the ajax with some template. For example if you have a mail field you could do:
and make a _addMail template:
This way you can do the ajax response using templates.
事实上,它确实来自与主表单相同的 _form 部分。 symfony 中的表单元素默认呈现为表格行,因此这可能是导致您困惑的原因。您能告诉我们您想做什么吗?
symfony 网站上有关于如何执行此操作的文档和非常详细的示例 参见此处。它非常深入,可能看起来有点令人畏惧,但我建议您仔细阅读它,并确保您花时间真正理解它。
In fact it does come from the same _form partial as the main form. Form elements in symfony by default render as a table row, so this might be what is causing your confusion. Could you please tell us what you're wanting to do.
There is documentation on how to do this and a very detailed example on the symfony website see here. It's pretty in depth and can look a bit daunting but I recommend you read through it and make sure you take the time to actually understand it.