maiconpinto / cakephp-adminlte-theme

CakePHP AdminLTE Theme
http://maiconpinto.github.io/cakephp-adminlte-theme/
MIT License
172 stars 111 forks source link

JsonView does not work #116

Open ashishonmobile opened 3 years ago

ashishonmobile commented 3 years ago

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 commented 3 years ago

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

fernaog commented 3 years ago

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

maiconpinto commented 1 year ago

Hi @ashishonmobile

Did you solve the problem or you need help?