cakephp 将 this->data 中的字段设置为数据库中的相关字段

发布于 2024-10-10 12:05:22 字数 681 浏览 0 评论 0原文

我正在尝试使用 meioupload 上传多个图像,如果我为每个数据字段设置 image.1.field 然后 image.2.field ,效果很好。然后循环并创建/保存而不是保存全部。

当我有一个字段用作图像文件夹中图像的子文件夹时,我的问题就出现了。 例如我有一个表单

image.1.product id image.1.艺术家 image.1.要上传的文件 图片.2.产品 ID image.2.艺术家 image.1.文件现在上传

,当项目保存时,所有数据都是正确的,包括产品ID的所属关系,除了第二张图片存储在错误的位置。 第一张图片存储在images/image.1.artist/文件中 第二张图片存储在 images/image.1.artist/image.2.artist/file 中

这非常烦人,这与 meioupload 行为将子文件夹设置为数组中的字段的方式有关。

我不得不采取的保存数据的方法是循环并创建然后保存值,这不是问题,但它显然不适用于这种设置子文件夹的方法。

因此,解决方案可能是简单地将第二个艺术家字段设置为空白,只为同一艺术家添加多个图像。

或者将艺术家的数据字段设置为图像所属的相关产品中艺术家的实际字段,但我似乎无法让它发挥作用?

所以问题是如何将此字段的值设置为每个单独创建/保存的数据库中已有的相关产品艺术家字段?

附:如果这有点啰嗦,我很抱歉。

I am trying to upload multiple images using meioupload which works fine if I set image.1.field and then image.2.field for each field of data. Then loop through and create/save rather than saveall.

My problem comes when I have field which is used as a subfolder for the image within an images folder.
for example I have a form

image.1.product id
image.1.artist
image.1.file to upload
image.2.product id
image.2.artist
image.1.file to upload

now when the items are saved, all data is correct including the belongsto relationship of product id, except the second image is stored in the wrong place.
The first image is stored in images / image.1.artist / file
the second image is stored in images / image.1.artist / image.2.artist / file

This is extremely annoying, and it is simply someting to do with the way the meioupload behaviour sets the subfolder to be a field from the array.

The way I have had to resort to saving the data is by looping through and creating then saving the values, which isnt a problem, but it obviously doesnt work with this method of setting a sub folder.

So a solution could possibly be to simply set the second artist field as blank and only add multiple images for the same artist..

Or to set the data field of artist to the actual field of artist in the related product the image will belong to, but I can't seem to get this to work?

So the question is how can I set the value of this field to the related products artist field that is already in the database for each seperate create/save?

ps. I am sorry if this is a bit long winded.

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

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

发布评论

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

评论(1

梦中楼上月下 2024-10-17 12:05:22

是的,问题来了,因为我将 $this->data 作为 2 个数组发送。解决方案是读取 this->image->product->field('artist') 并将其设置为 this->data['Image'][1]['artist']。

这样,它将第一个数组中的字段设置为艺术家,在这个特定的 meioupload 行为中,该字段将滚动到第二个数据数组,因此图像上传(然后将带有 / 后缀)这允许我上传图像到相应的艺术家目录,同时创建 3 个缩略图并保存关系、文件信息等。

我发现这似乎对加载图像没有影响(即使显示代码实际上有两个 / ,图像也能正常工作,因为第二个图像将作为 /dir/artist/ 保存在数据库中摆出保存在 /dir/artist 的第一个图像)

如果有人有一种巧妙的方法一次调用 meioupload 一个,那么这将有望避免这个小问题,然后越来越多的图像可以添加到同一表单中。唉,我还不够聪明,不知道该怎么做。
任何帮助将不胜感激!

Right so the problem came because I was sending $this->data as 2 arrays. The solution was to read this->image->product->field('artist') and set it to this->data['Image'][1]['artist'].

This way it sets the field in the first array to artist, which in this particular meioupload behaviour will roll over to the second array of data and hence the image upload (which will then be suffixed with a /) This allows me to upload the images to their corresponding artist directory whilst creating 3 thumbnails and saving the relations, file info and so on.

I found that this doesn't seem to make a difference to loading the images (images work fine even though the display code effectively has two / in it, because the second image will be saved in the database as /dir/artist/ as a pose to the first one which is saved /dir/artist)

IF anyone has an ingenious way to call meioupload one at a time then this would hopefully avoid this slight issue, and then more and more images could be added into the same form..alas I am not clever enough to know how to do this yet..
Any help would be much appreciated!!!!

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