简体   繁体   中英

CakePHP: How do you avoid the use of a template when rendering JSON?

I'm presently working with a new project in CakePHP, and when I add a json request to a controller, CakePHP looks for a matching view template in the views folder. This behavior would be fine for regular pages, but every single one of my json view templates is completely empty . I use a "json" layout that looks like this:

<?php
Configure::write('debug', 0);
echo json_encode($json_output);
?>

I realize a partial solution might be to simply "touch" a file for every json view that I create, but that involves SSHing into the server and doing a lot of overhead stuff. Is there a way to simply tell CakePHP to use just the layout for a given view?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM