Symfony(学说):“嵌入”外来形式

发布于 2024-08-20 14:10:08 字数 631 浏览 6 评论 0原文

我在使用 Symfony 时总是遇到这样的问题: 假设您有一个产品,并且您想为其添加一些照片。 我想这样没有问题:

Product:
  columns:
    name: { type: string(255), notnull: true, unique: true }

Photo:
  columns:
    product_id:  { type: integer, notnull: true }
    name:         { type: string(255) }
    order:     { type: integer, notnull: true }
  relations:
    Product: { onDelete: CASCADE, local: product_id, foreign: id, foreignAlias: Photos } 

但问题是我希望我的用户在添加/编辑产品时直接添加照片。这听起来很基本,我保证在问你之前我花了几个小时寻找答案! 当然,最好的方法是使用一些ajax来连续添加所有文件,但是如果他可以多次提交,那么一切准备就绪就更好了(通常我使用单独的“照片”表单来完成此操作,在你每次都必须搜索产品才能链接它......

所以问题是“嵌入”或“嵌套”(我不知道确切的词)表单中的异物。

I always have this kind problem with Symfony:
Let's say you have a product, and you want to add it some photos.
I guess like this there's no problem:

Product:
  columns:
    name: { type: string(255), notnull: true, unique: true }

Photo:
  columns:
    product_id:  { type: integer, notnull: true }
    name:         { type: string(255) }
    order:     { type: integer, notnull: true }
  relations:
    Product: { onDelete: CASCADE, local: product_id, foreign: id, foreignAlias: Photos } 

But the thing is i want my the user to add the photos directly when he adds/edits a product. It sounds quite basic, I promise I spent hours looking for the answer before asking you !
Of course the best would be to do this with some ajax to add all the files in a row, but if he could do it submitting several times it would all ready be better (usually I did this with a separate "photo" form, in which you had to search the product every time to link it...

So the problem is "embedding" or "nesting" (i don't know the exact word) the foreign objects in the form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-08-27 14:10:08

我不久前写了一篇关于嵌入子表单并使用ajax添加照片< /a>.更多有用信息此处以及此处。在这篇文章你会发现一种不同的方法。虽然 ajax 用于添加子表单,但正如您所说,它并不完全是您想要的,这些帖子包含您可以用来实现自己的嵌入式内容的技术。因此,我建议您阅读有关绑定过程如何工作的内容,并耐心等待,因为这是 symfony 的一个棘手部分,但它是有回报的!

I wrote some time ago a post about embedding subforms and add photos with ajax. More useful information here and here. In this post you will find a different approach. Although ajax for adding subforms it is not exactly what you want, as you say, these posts contain techniques that you can employ to implement your own embedded stuff. So I'd suggest you to read about this, how the bind process work, and take it with patience, because it is a tricky part of symfony, but it pays off!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文