I figured out the problem.

I put this inside my controller and it started working.

public $components = array('RequestHandler');
I previously only had it here App::uses('RequestHandler');



On Fri, Feb 17, 2012 at 6:46 PM, Justin Edwards <[email protected]>wrote:

> I was under the assumption from the documentation that extensions json and
> xml when setup properly would automatically render when using _serialize.
> No matter what I was doing, using cakesite.com/posts.json it would not
> render without a layout if I had an index.ctp.   It didn't even touch
> json/index.ctp.
>
> I finally was able to get some progress, realizing that I could use
> $this->viewClass = 'Json';
>
> The problem with this is that I would have to write a lot more code if I
> wanted the .json extension to output properly using if statements.   And
> I'd really like a solution where I could use minimal code and use REST on
> my controllers wherever I wanted.
>
> In previous versions of cake the .json extension was working properly with
> $subDir, but the latest 2.1 doesn't seem to be doing so.
>
> I don't know if I'm not understanding something, or there is a problem in
> 2.1.
>
>
>
> //controller
>
>       $posts = $this->Post->find('all');
>
>                   $data = array('posts' => $posts);
>
>                   $this->viewClass = 'Json';
>
>                   $this->set($data);
>
>                   $this->set('_serialize', 'posts');
>
>
> Any help / input would be appreciated.
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to