3

I have a table with nodes that acts as a tree. I have a tree structure:

Null
Null
-Child
--ChildofChild
--ChildofChild
-Child
Null

etc...

I want to get it into an array structure like this:

array(
   0 => array( id => ''),
   1 => array( id => '', array( 
        0 => array( id => '', 
             0 => array(
                  id => '',
                 )
             1 => array (
                  id =>''),
        1 => array(id => '')      
   2 => array ( id => '')

I have missed some closing brackets, but the idea is to get an array including an array for every node inside the array of its parent. all arrays will contain just the node's id. I tried with find('threaded) but I can't get it as I want. Any ideas??

1
  • Please read carefully the CakePHP Docs at Tree. The solution is there Commented Feb 18, 2013 at 14:38

1 Answer 1

7

This is what you'r looking for:

$categories = $this->Category->find('threaded', array(
    'fields' => array('id', 'parent_id', 'name'),
    'order' => array('lft ASC') // or array('id ASC')
));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.