开发者

cakephp save array

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....
)

thanks


2 choices:

  1. Format the array as required by Model::saveAll()
  2. Loop through the array calling Model::create(), then Model:save()

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜