views:

173

answers:

1

Hi folks,

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 submiting 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.

Thank's

+2  A: 

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!

nacmartin
great stuff, thanks :)
Julien
+1 I just stumbled upon your answer, and it helped me a lot. Thanks!
Arms