Cakephp gets tree into array

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

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

      

etc...

I want to get it in 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 missed some of the closing brackets, but the idea is to get an array containing an array for each node inside its parent's array. all arrays will only contain the node id. I've tried with find ('threaded) but I can't seem to get it the way I want. Any ideas??

+3


source to share


1 answer


This is what you are looking for:



$categories = $this->Category->find('threaded', array(
    'fields' => array('id', 'parent_id', 'name'),
    'order' => array('lft ASC') // or array('id ASC')
));

      

+7


source







All Articles