Welcome Guest, Not a member yet? Register   Sign In
problem with response and entity
#1

(This post was last modified: 02-27-2019, 12:06 PM by keulu.)

How do you do guys ? nice ? ok 'cause I have a problem Big Grin

if my model return and object Entity, If i ask in my controller the typeof $entity->createdAt, it answer CodeIgniter\I18n\Time Object ok nice (magical mutations and casts works) BUT....

if i do $this->response->SetJson($entity); i got an empty object. no cast, no magical conversions, all fields are protected so the json_encode can't access to this fields. The same with a var_dump or print_r. fields are not converted.


How can i send over a REST application the correct representation of my entity ?

Note :

If i put some fields"public" in my entity, i can see it in my response but without magical conversion...

is that a bug or a workaround ? maybe someone did this trick ?

the worst is that if i do $this->response->SetJson($entity->created_at); I've got an error 500 about a problem with format.

Code:
Argument 1 passed to CodeIgniter\Format\JSONFormatter::format() must be of the type array, object given, called in /www/api/system/HTTP/Response.php on line 551
Reply


Messages In This Thread
problem with response and entity - by keulu - 02-27-2019, 12:01 PM
RE: problem with response and entity - by ciadmin - 02-27-2019, 12:21 PM
RE: problem with response and entity - by keulu - 02-27-2019, 01:24 PM
RE: problem with response and entity - by ciadmin - 02-27-2019, 01:33 PM
RE: problem with response and entity - by keulu - 02-27-2019, 01:39 PM
RE: problem with response and entity - by keulu - 02-27-2019, 01:40 PM
RE: problem with response and entity - by keulu - 02-28-2019, 11:04 AM
RE: problem with response and entity - by keulu - 02-28-2019, 11:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB