Welcome Guest, Not a member yet? Register   Sign In
Query return empty CSP object when wrapped?
#1

(This post was last modified: 10-13-2021, 01:05 AM by blaasvaer. Edit Reason: Fucked up editor! )

If I do this in my controller:

PHP Code:
return $this->response->setJSON($this->model->find($id)); 

I properly get the data I want as an object:

Code:
{
    "id": "3",
    "name": "my item",
    "meta": null,
    "created_at": "2020-12-22 15:19:50",
    "updated_at": null,
    "deleted_at": null
}

But if I wrap it like this:


PHP Code:
$response = array();

$response["data"] = $this->response->setJSON($this->model->find($id)); // exactly as the above

$response["fields"] = $this->model->getFieldData$resource );

return 
$this->response->setJSON($response); 

I get this:


Code:
{
  "data": {
    "CSP": {} <-- why this empty object all of a sudden?
  },
  "fields": [ < this data is fine > ]
}

Why the empty CSP object all of a sudden?

I tried enabling CSP in the Config/App.php but that didn't change a thing ... and to be honest I don't like the 'random' character this has to it.

NOTE: And by the way; this editor has serious problems when formatting and previewing posts ... al content gets scrambled and tons of new lines get added. It's basically a nightmare to use. I usually have to use a text editor and copy/paste and reformat everything everytime I make an edit to a post. Someone gonna fix this at some point?

Weeeeeeell, that made perfectly sense. I should remove the 'response' part when adding it to an array ... sigh!

Change this:
PHP Code:
$response["data"] = $this->response->setJSON($this->model->find($id)); 


To this:
PHP Code:
$response["data"] = $this->model->find($id); 
Reply
#2

(10-13-2021, 12:38 AM)blaasvaer Wrote: NOTE: And by the way; this editor has serious problems when formatting and previewing posts ... al content gets scrambled and tons of new lines get added. It's basically a nightmare to use. I usually have to use a text editor and copy/paste and reformat everything everytime I make an edit to a post. Someone gonna fix this at some point?

Yeah the editor is not very good. That's why I almost always type in "source code" mode. Click the last icon in the toolbar, or hit ctrl-shift-s to switch between the 2 modes (visual vs. source code)
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB