CakePHP 保存多行

标签 cakephp cakephp-2.0

我正在使用“User”和“UserImage”这两个模型。我将在其中将多行保存到 user_images 表中。UserImage 的 View 如下所示。

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'));

那么如何保存多行..

最佳答案

如果涉及的模型比较多,需要指定每个字段的模型。 此外,您需要为每条记录指定相关字段(user_id)。

试试这个:

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

加上使用它来保存多个记录和多个模型:

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

关于CakePHP 保存多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396708/

相关文章:

mysql - CakePHP 1.3 : How to represent the following MySQL code with Count(*) AS Total

cakephp - 调试在 get 中发送的 CakePHP HttpSocket 数据

javascript - 根据复选框禁用/启用文本框

CakePHP 2.0 不使用我的 Ajax 布局

php - 如何使用 PHP 中的 Authorize.net 以编程方式退款?

javascript - 使用 AngularJS 选择多个显示名称而不是 ID

php - 在cakephp中更新表时如何删除条目?

php - CakePHP Auth 组件使用 $this->Auth->login() 时未登录;

php - 在 CakePHP 3 中,andWhere()、orWhere()、where() 方法的计算顺序是什么?

facebook - HTTPS 而非 HTTP 中的 CakePHP Facebook 插件错误