Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7736579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:46:18+00:00 2026-06-01T07:46:18+00:00

I have created a RESTful PHP web service using Lithium which contains comments, each

  • 0

I have created a RESTful PHP web service using Lithium which contains comments, each comment can have a parent comment allowing comments to be infinitely recursive.

I have set up the relationship within my model using the correct key.

My data is currently formatted list this (using Model::()):

Array
(
    [1C19FA9D-0432-A382-5236-2C59E0967F58] => Array
        (
            [id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
            [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
            [parent_id] => 
            [user_id] => 4
            [comment] => This is a test
            [created] => 2012-03-16 16:41:33
            [updated] => 
        )

    [3B2350BA-9BA7-D7D4-2ED4-42BD40BC1AF0] => Array
        (
            [id] => 3B2350BA-9BA7-D7D4-2ED4-42BD40BC1AF0
            [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
            [parent_id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
            [user_id] => 543
            [comment] => Testing
            [created] => 2012-03-16 17:25:47
            [updated] => 
        )

    [4CFD2D8B-D05F-7C8A-E2A9-38D5677280A9] => Array
        (
            [id] => 4CFD2D8B-D05F-7C8A-E2A9-38D5677280A9
            [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
            [parent_id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
            [user_id] => 53
            [comment] => A Test
            [created] => 2012-03-16 17:25:38
            [updated] => 
        )
)

And I would prefer it was formatted like this

Array
(
    [0] => Array
        (
            [id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
            [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
            [parent_id] => 
            [user_id] => 4
            [comment] => This is a test
            [created] => 2012-03-16 16:41:33
            [updated] =>
            [comment] => Array(
                [0] => Array
                (
                    [id] => 3B2350BA-9BA7-D7D4-2ED4-42BD40BC1AF0
                    [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
                    [parent_id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
                    [user_id] => 543
                    [comment] => Testing
                    [created] => 2012-03-16 17:25:47
                    [updated] => 
                )
                [1] => Array
                (
                    [id] => 3B2350BA-9BA7-D7D4-2ED4-42BD40BC1AF0
                    [page_id] => 0384F94C-8B99-F692-62D0-7B24B0885257
                    [parent_id] => 1C19FA9D-0432-A382-5236-2C59E0967F58
                    [user_id] => 543
                    [comment] => A Test
                    [created] => 2012-03-16 17:25:47
                    [updated] => 
                )
            )
        )
)

Is there a recursing function built in to Lithium or is this something I would have to create myself? Please also note the changes in Keys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:46:21+00:00Added an answer on June 1, 2026 at 7:46 am

    To fix this I actually ended up generating my own array from the results as follows:

           public function index($page_id) {
                $page = Pages::first($page_id);
                $site = Sites::first($page->site_id);
                $comments = Comments::all(array('conditions' => array('page_id' => $page->id, 'comment_id' => NULL)));
    
                if ($this->request->type == 'JSON')
                    $comments = $this->_recursiveComments($comments, $page);
    
                return compact('comments', 'page', 'site');
            }
    
            protected function _recursiveComments($comments, $page) {
                foreach($comments as $c) {
                    $children = Comments::all(array('conditions' => array('comment_id' => $c->id)));
                    $c->children = $children;
    
                    $this->_recursiveComments($children, $page);
                }
    
                return $comments;
            }
    

    That way I could just do a foreach($comments as $key => $value) loop and avoid the random keys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have created RESTful web services using Spring's REST support. We need to call
I have a REStful WCF web service (using a substantially modified WCF Rest Starter
We have created a WCF RESTful service for a WPF(UI) Application. The UI sends
I have created a PHP-script to update a web server that is live inside
So I am using Limonade PHP which has a RESTful design which emulates PUT,
I have an Appointment model, which can be created via different routes (from Tutor
As I understand it, using a hypertext-driven RESTful Web service, a client is not
We have a Spring web application created using Spring MVC 3.0 In the same
I'm looking for examples of how others have created a RESTful service that supports
I would like to create a RESTful web service that I can deploy on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.