Redundant ModelName in CakePHP find Results Redundant ModelName in CakePHP find Results json json

Redundant ModelName in CakePHP find Results


In your controller, instead of serializing the results of the find, serialise a level deeper.

Assuming CakePHP 2:

$things = $this->Thing->find('all');$things = Set::extract('/Thing/.', $things);

Now your results should be free of the extra level in your JSON.

The alternative, lengthy way of doing it is to for loop over the results:

foreach ($things as $k => &$v) {    $v = $v['Thing']}

After that, your $things will have removed the extra level of keys.


For later versions of Cake, use $things = Set::extract($things, '{n}.Thing');