phpcakephpsave

CakePHP not saving data to database


I am currently trying to save various records into the same model.

I have read the docs concerning format of data, and my custom array of data conforms to this.

This is my function:

$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.'));
}

I get no validation errors. The data passed to this function, looks like follows:

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

(I know this is weird data, but it's test data)

** I have tried the following methods of saving, all of them fail:

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

None of them work. Please help, what am I doing wrong?


Solution

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