Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonView does not work #116

Open
ashishonmobile opened this issue Mar 11, 2021 · 3 comments
Open

JsonView does not work #116

ashishonmobile opened this issue Mar 11, 2021 · 3 comments
Labels

Comments

@ashishonmobile
Copy link

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
Copy link
Author

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
Copy link

fernaog commented Jun 18, 2021

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
Copy link
Owner

Hi @ashishonmobile

Did you solve the problem or you need help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants