gpt4 book ai didi

CakePHP 不将数据保存到数据库

转载 作者:行者123 更新时间:2023-12-02 10:04:48 24 4
gpt4 key购买 nike

我目前正在尝试将各种记录保存到同一模型中。

我已阅读有关数据格式的文档,并且我的自定义数据数组符合此要求。

这是我的功能:

$k = 0;
foreach($this->request->data['FileData'] as $data) {
$name = substr($data['name'],0,strpos($data['name'],'_'));
$ext = substr($data['name'],strrpos($data['name'],'.')+1);
$display_name = str_replace('.'.$ext,'',str_replace($name . '_','',$data['name']));
$Clinic = $this->Clinic->find('first',
array(
'conditions' => array(
'Clinic.name' => strtoupper($data['owner'])
),
'fields' => array('id')
)
);
$Data['Upload'][$k]['clinic_id'] = $Clinic['Clinic']['id'];
$Data['Upload'][$k]['file_name'] = $data['name'];
$Data['Upload'][$k]['display_name'] = $display_name;
$Data['Upload'][$k]['extension'] = $ext;
$k++;
}
$this->Upload->create();
if ($this->Upload->saveMany($Data,array('deep'=>true))) { ** READ BELOW
$this->Session->setFlash(__('The upload has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The upload could not be saved. Please, try again.'));
}

我没有收到任何验证错误。传递给该函数的数据如下所示:

array(
'Upload' => array(
(int) 0 => array(
'clinic_id' => '72',
'file_name' => 'MAHLUNGULU CLINIC_0_Guide_Tax_Season_2012_Insert_Afrikaans.pdf (6).pdf',
'display_name' => '0_Guide_Tax_Season_2012_Insert_Afrikaans (6)',
'extension' => 'pdf'
),
(int) 1 => array(
'clinic_id' => '79',
'file_name' => 'ZAMA ZAMA CLINIC_1377256_515345465221385_1613340746_n.jpg',
'display_name' => '1377256_515345465221385_1613340746_n',
'extension' => 'jpg'
),
(int) 2 => array(
'clinic_id' => '72',
'file_name' => 'MAHLUNGULU CLINIC_07reader.xlsx',
'display_name' => '07reader',
'extension' => 'xlsx'
),
(int) 3 => array(
'clinic_id' => '79',
'file_name' => 'ZAMA ZAMA CLINIC_13-disturbed-i_still_havent_found_what_im_looking_for.mp3',
'display_name' => '13-disturbed-i_still_havent_found_what_im_looking_for',
'extension' => 'mp3'
)
)
)

(我知道这是奇怪的数据,但它是测试数据)

** 我尝试过以下保存方法,均失败:

$this->Upload->saveMany($Data,array('deep',true));
$this->Upload->saveMany($Data['Upload'],array('deep',true));
$this->Upload->save($Data);
$this->Upload->save($Data['Upload']);
$this->Upload->saveAll($Data);
$this->Upload->saveAll($Datap['Upload']);

它们都不起作用。请帮忙,我做错了什么?

最佳答案

$data['modelname']['dbfieldname']$this->modelname->save(data);

关于CakePHP 不将数据保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com