cakephp保存数组 [英] cakephp save array

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

问题描述

什么是使用php(cakephp)保存以下数组的有效方式?
每个值需要进入表中的新行吗?

what would be the efficient way of saving the following array using php (cakephp)? each value needs to go into a new row in the table?

Array
(
    [0] => 6786754654
    [1] => 5643564545
    [2] => 344544545
    [3] => 233245654654
    [4] => 453454654654
    [5] => 6546542323
    [6] => 654654654
    [7] => 645654654
    etc....
)

感谢

推荐答案

2个选择:


  1. 根据模型所需格式化数组:: saveAll()

  2. 循环遍历调用Model :: create()的数组,然后Model:save()

我推荐选项1,因为你可以使用Model :: saveAll($ data,array('validate'=>'first'));以确保所有值在保存任何值之前都有效。

I'd recommend option 1 as you can use Model::saveAll($data, array('validate' => 'first')); to ensure that all values are valid before saving any of them.

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

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