cakephp-adminlte-theme icon indicating copy to clipboard operation
cakephp-adminlte-theme copied to clipboard

JsonView does not work

Open ashishonmobile opened this issue 3 years ago • 3 comments

when I try to access the http://localhost:8765/users.json it does not return me the json data

I have below function in AppController public function beforeRender(EventInterface $event) { $this->viewBuilder()->setTheme('AdminLTE'); $this->viewBuilder()->setClassName('AdminLTE.AdminLTE'); }

but If I comment the line ' $this->viewBuilder()->setClassName('AdminLTE.AdminLTE');' I am able to get json data from server.

so It seems the issue is somewhere after setting the ClassName

I wish this could be fixed.

Regards, Ashish

ashishonmobile avatar Mar 11 '21 23:03 ashishonmobile

Finally, I have found another way to solve this

below is my code ` public function beforeRender(EventInterface $event) { $this->viewBuilder()->setTheme('AdminLTE');

    if($this->getRequest()->getHeader('Accept')[0] === 'application/json')
    {
        $this->viewBuilder()->disableAutoLayout();
    }else {
        $this->viewBuilder()->setClassName('AdminLTE.AdminLTE');
    }
}`

Hope this will help other people to fix the problem.

Regards, Ashish

ashishonmobile avatar Mar 15 '21 23:03 ashishonmobile

Finally, I have found another way to solve this

below is my code ` public function beforeRender(EventInterface $event) { $this->viewBuilder()->setTheme('AdminLTE');

    if($this->getRequest()->getHeader('Accept')[0] === 'application/json')
    {
        $this->viewBuilder()->disableAutoLayout();
    }else {
        $this->viewBuilder()->setClassName('AdminLTE.AdminLTE');
    }
}`

Hope this will help other people to fix the problem.

Regards, Ashish

Thank you, you saved my day

fernaog avatar Jun 18 '21 22:06 fernaog

Hi @ashishonmobile

Did you solve the problem or you need help?

maiconpinto avatar Nov 23 '22 02:11 maiconpinto