Closed dhrrgn closed 13 years ago
Making this a Bug. It was submitted by koichi h Today.
Commenting to be notified of changes.
I'm speculating here but I think the problem is this line: https://github.com/fuel/core/blob/develop/classes/format.php#L215
My assumption is that json_encode() will run a get_object_vars() on the Model_User object, which will return an empty array as all the properties are protected or private. The way this could be solved is by doing something like this:
// Encode as JSON
public function to_json()
{
$data = $this->_data instanceof ArrayAccess ? $this->to_array($this->_data) : $this->_data;
return json_encode($data);
}
Or do this by converting objects to arrays with a _from...() method that can use either get_object_vars() or the above solution.
As it currently doesn't work at all I submitted my fix, don't have the time to properly test it though.
There's a bug with JSON output in a REST controller. Here's some code:
This will output:
I have two users in my test environment, so having 2 json values would be correct, but they're empty. By uncommenting the print_r I get my 2 results so the $users variable is correct.
Also, if I change config/rest.php back to xml, it outputs everything correctly. More details here: http://fuelphp.com/forums/topics/view/974