Hi,
If I pass data from the client using:
Code:
(ajax) ...
data: $(formData).serializeArray();
...
I can easily update a record accessing the data like this:
Code:
$data = $this->request->getRawInput();
passing it to the model like this:
Code:
$this->model->update($id, $data);
If I wrap that in an object along other data like this:
Code:
_data = {
formData: $(formData).serializeArray(),
other: other_data
};
(ajax) ...
data = _data;
...
And try to access the data on the server doing this:
Code:
$data = $this->request->getRawInput();
$this->model->update($id, $data["formData"]);
It explodes. Now, I've tried fiddling with the format in the ways I can think of ... no luck.
Can someone explain why I cannot access the data anymore just because I give it a 'level deeper' ... I don't get it?
By the way; I am aware, that I pass an object in the second version and an array in the first ... but no matter HOW I try do json_decode/encode I simply cannot pass the data to the update method on the model ... I can var_dump the result just fine ... but 'something' is happening during the pass to the model (I guess).
When I check the output I see some difference ... but cannot figure out where the 'difference' happens. Notice the indexes ( [0] => etc ) in the NOT WORKING OUTPUT.
WORKING OUTPUT:
Code:
responseText: "array(3) {\n
[\"name\"]=>\n
string(12) \"My Home page\"\n
[\"title\"]=>\n
string(12) \"Saving title\"\n
[\"content\"]=>\n
string(18) \"Saving content …\"\n
}\n
RESPONSE:
{\"id\":\"1\",\"name\":\"My Home page\",\"title\":\"Saving title\",\"content\":\"Saving content …\",\"created_at\":\"2020-10-21 20:53:27\",\"updated_at\":null,\"deleted_at\":null}"
NOT WORKING OUTPUT:
Code:
responseText: "array(3) {\n
[0]=>\n
array(2) {\n
[\"name\"]=>\n
string(4) \"name\"\n
[\"value\"]=>\n
string(12) \"My Home page\"\n
}\n
[1]=>\n
array(2) {\n
[\"name\"]=>\n
string(5) \"title\"\n
[\"value\"]=>\n
string(13) \"Saving titlen\"\n
}\n
[2]=>\n
array(2) {\n
[\"name\"]=>\n
string(7) \"content\"\n
[\"value\"]=>\n
string(18) \"Saving content …\"\n
}\n
}\n
RESPONSE:
\"Resource not updated\""