cakephp save array

纵饮孤独 提交于 2020-01-25 10:19:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/1737206/cakephp-save-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!