On Friday, July 27, 2012 10:58:10 AM UTC-4, Falagar wrote:
--I cannot get this to work in 2.2. This is what I have tried:
First I just followed the book to create JSON views (http://book.cakephp.org/2.0/
en/views/json-and-xml-views. Works great. I get JSON data back.html). Then I followed the CacheHelper instructions (http://book.cakephp.org/2.0/
en/core-libraries/helpers/ I un-commented Cache.check in core.php, added the CacheHelper in my Controller and defined $cacheAction. This works great for HTML Views. But, for JSON views nothing gets cached unfortunately.cache.html). I found this post: http://lars-schenk.com/cached-
json-or-xml-view-with-cakephp/ that ran into a similar issue (albeit in an earlier version of Cake that didn't have JsonView yet).523 So I tried to use his method, and apply it to 2.2. I took Router::parseExtensions( 'json' ) out, took the RequestHandler out, created a json.ctp layout file.
<!--nocache--><?php configure::write('debug',0); // surpress all debug output on json views header('Content-type: text/x-json'); ?><!--nocache--><?php echo $this->fetch('content'); ?>
a feed.ctp view file
<?php echo json_encode( $data ); ?>
and changed my controller action to just set the layout and data
$this->layout = 'json'; $this->view = 'feed'; $this->set( 'data', $data );
This works somewhat. I get the JSON file the first time, but when I request that action again, the response contains
<!--nocache:001--><!--nocache:
002--> before the actual JSON data, so it won't work for my client app. I can see that chunk of text in the actual cache file as well, which I think is the problem.
So I am not quite sure how to proceed.
Am I just missing something painfully obvious?
Any help would be greatly appreciated.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment