This issue is started to do my head in! I am trying to build a basic invoice system for my site, which is using CakePHP.
However, I can save almost all of the data without any issues at all, its when I want to save two fields, 'workdes' and 'price' which are arrays, every time I try and save the data I get an error of Array to String!
Heres my code:
$test = $this->request->data;
foreach($test as $test2 => $tets3) {
$this->Invoicedata->create();
$InvoiceGroupData = array(
'Invoicedata' => array(
'workdes' => $this->request->data['workdes'],
'price' => $this->request->data['price']
)
);
//debug($InvoiceGroupData); die();
$this->Invoicedata->saveMany($InvoiceGroupData);
}
This is what is inside $this->request->data:
'workdes' => array(
(int) 0 => 'dfgdfg',
(int) 1 => 'sswd'
),
'price' => array(
(int) 0 => '500',
(int) 1 => '100'
)
This is just test data, I can have anything from one input or five. So What I am doing wrong? I thought that the use of SaveMany was that is did save Arrays into the database.
The table / model name I am trying to save to is call Invoicedata, and the two tables within that are 'workdes' and 'price'.
Anything else I have not put into the question and is needed, please ask!
Please Help....
Many Thanks
Glenn.
UPDATE ::
These are the two sections of code I have tried, and I am still getting Array to String issue!!
CODE TRY 1:
$WorkHolder = $this->request->data['workdes'];
$PriceHolder = $this->request->data['price'];
$MyData = array(
array('Invoicedata' => array('workdes' => $WorkHolder)),
array('Invoicedata' => array('price' => $PriceHolder)),
);
foreach($MyData as $test2 => $test3) {
$this->Invoicedata->create();
//debug($test3);
$this->Invoicedata->saveMany($test3);
}
CODE TRY 2:
$WorkHolder = $this->request->data['workdes'];
$PriceHolder = $this->request->data['price'];
$MyData = array(
array('Invoicedata' => array('workdes' => $WorkHolder)),
array('Invoicedata' => array('price' => $PriceHolder)),
);
//debug($MyData); die();
$this->Invoicedata->saveMany($MyData);
One with a foreach loop and one without, Code try 2 is what I tried 1st, now my code looks like code try 1. I have changed, or at lest i think I have changed my array data to that of want CakePHP needs it to be, so what am I doing wrong?