CakePHP保存多行 [英] CakePHP save multiple rows

查看:168
本文介绍了CakePHP保存多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用两个模型'User'和'UserImage'..我在哪里将多行保存到user_images表.. UserImage的视图如下..

I am using two models 'User' and 'UserImage'.. Where in i am going to save multiple rows into user_images table.. The view for UserImage is below..

echo $this->Form->input('UserImage.0.photo');
echo $this->Form->input('UserImage.1.photo');
echo $this->Form->input('user_id');
echo $this->Form->end(__('Submit'));

然后如何保存多行..

Then how to save multiple rows..

推荐答案

如果你有更多的模型,你应该指定每个字段的模型。
此外,您需要为每个记录指定相关字段(user_id)。

You should specify the model of each field if you have more models involved. Also, you need to specify for each record the related field (user_id).

尝试:

echo $this->Form->input('UserImage.0.user_id');
echo $this->Form->input('UserImage.1.user_id');

此外还可用于保存多个记录和多个模型:

Plus use this to save multiple records and multiple models:

$this->UserImage->saveAll($this->request->data);

这篇关于CakePHP保存多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆