cakephp-rest icon indicating copy to clipboard operation
cakephp-rest copied to clipboard

How can i get a result without named variable

Open MemoRodMx opened this issue 4 years ago • 1 comments

Hi, i'm trying to get a serialized result to ommit the name or variable on result.

How can i get the same result like using the $this->set('_serialize', 'varname'); in this plugin?

i want to get a result like this

{ "status": "OK", "result": { "falanu": [ "dhikanu", "tamburo" ] } }

instead of:

{ "status":"OK","result": { "bar": { "falanu": [ "dhikanu", "tamburo" ] } } }

without putting the name variable what i'm using in the response

thank you

MemoRodMx avatar Apr 15 '20 23:04 MemoRodMx

Good question! As of now, there is no automated solution for this. But you can do that by adding an extra key to your response array. See following example,

public function bar()
{
    $bar = [
        'bar' => [
            'falanu' => [
                'dhikanu',
                'tamburo'
            ]
        ]
    ];
    
    $this->set(compact('bar'));
 }

narendravaghela avatar Apr 16 '20 07:04 narendravaghela