2

I'm using Filestore to make uploads in a form. It's a great implementation but I've a doubt about associating that file uploaded with a register in a table.

When I run the filestore.001.sql, it add 4 tables in Database (filestore_image, filestore_file, filestore_volume, filestore_extension).

Then in anoter table I have:

id
field1
idfile

I was thinking in how to do that association when I submit the form. Maybe a dsql() and then selecting the last inserted file, but I don't know if this is the best option.

Thanks Alejandro

AJM.MARTINEZ
  • 477
  • 2
  • 10

1 Answers1

0

When you add a image field to a form, it will return you ID (or list of uploaded file id's) on submission. So theoretically user can upload image and never submit form, hence it wouldn't be associated.

You can have the following table:

  • id
  • name
  • picture_id

and define picture as type image, there should be examples on the site - it will automatically receive ID from the filestore_file table.

There is another way you can do and it's exactly how Filestore_Image is being built. You can make your own model, and link it with necessary image and use that for your image field. Since it's your model, you can now control what happens before inserting, you can override beforeInsert and afterInsert events to build the proper associations.

Both methods have their own uses, pick the one which you like.

romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • OK, the first point I think its good. But how do I access that id on the $_GET variable ?. Thanks again – AJM.MARTINEZ Sep 01 '11 at 15:59
  • If you are loosing the $_GET variables on form submissions, you should make them sticky with $this->api->stickyGET('id'); – romaninsh Sep 01 '11 at 16:07