Maybe you simply have to preprocess the array before send it to the
view.
Like this:
posts_raw = $this->Post->find('all', array('order'=>
'Post.id ASC'));
if (isset($posts_raw['Post'])) {
$this->set('posts', $post_raw['Post']);
}
Try it and tell me!
Greetings.
On 2 jun, 23:18, mxmtycoder <[email protected]> wrote:
> Hi,
>
> I'm new with cakephp,
> I've been following the blog posts tutorial and some other pages about
> exporting to json
>
> here is a fragment of the controller
>
> var $name = 'Posts';
> var $components = array('RequestHandler');
> var $helpers = array('Html','Javascript','Ajax');
>
> function beforeFilter() {
> $this->RequestHandler->setContent('json', 'text/x-json');
> }
>
> function index() {
> $this->set('posts', $this->Post->find('all', array('order'=>
> 'Post.id ASC')));
> }
>
> the model doesn't have any differences from the tutorial,
> the json I got is the following:
>
> [{"Post":{"id":"1","title":"The title","body":"This is the post
> body.","created":"2009-06-02 15:59:48","modified":null}},
> {"Post":{"id":"2","title":"A title once again","body":"And the post
> body follows.","created":"2009-06-02 15:59:48","modified":null}},
> {"Post":{"id":"3","title":"Title strikes back","body":"This is really
> exciting! Not.","created":"2009-06-02 15:59:48","modified":null}}
> ]
>
> I would like to have the json as
>
> [{"id":"1","title":"The title","body":"This is the post
> body.","created":"2009-06-02 15:59:48","modified":null},
> {"id":"2","title":"A title once again","body":"And the post body
> follows.","created":"2009-06-02 15:59:48","modified":null},
> {"id":"3","title":"Title strikes back","body":"This is really
> exciting! Not.","created":"2009-06-02 15:59:48","modified":null}
> ]
>
> Thanks,
> Pablo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---