Also note that one issue with your reorderAll() function is that it loops through all non-empty parent IDs. The only problem with this is that top-level items WILL have an empty parent.
On Nov 3, 10:27 am, Kerr <[email protected]> wrote: > To be more specific in addressing, "I'm also still not > sure if reorder() recurses as far as it can, or just one level. " -- > Yes, it will recurse the tree until it finds no children in all > affected branches. > > On Nov 2, 8:25 pm, Kerr <[email protected]> wrote: > > > Hi, I've been playing around with thetreefunctionality as well. > > Looking at the code, you'll notice that thereordermethod calls > > itself recursively. If you want toreorderthe entiretree, simply > > pass no arguments... e.g. > > > $this->reorder(); > > > Overall, I'm pretty impressed so far with how easy thetreemethods > > make it to deal with the adjacency list hierarchy model. I've had to > > code this kind of stuff from the ground up in SQL Server, and it was a > > major PITA. > > > On Oct 29, 5:27 am, MonkeyGirl <[email protected]> wrote: > > > > Hi. > > > > I'm trying to order atreesuch that for any given node on thetree, > > > all its children appear alphabetically, including the top level. > > > > If I understand thereorder() method correctly (it has sparse > > > documentation > > > athttp://book.cakephp.org/view/229/Advanced-Usage#reorder-518 > > > but the API > > > athttp://api.cakephp.org/class/tree-behavior#method-TreeBehaviorreorder > > > is more informative), then you need to pass it the IDs that need > > > editing. I want toreorderthe whole entiretreethough, so I made my > > > own reorderAll() method in /app/app_model.php: > > > > function reorderAll($options = array()) { > > > $parentIDs = $this->find('list', array( > > > 'fields' => array( > > > 'parent_id' > > > ) > > > )); > > > > $parentIDs = array_unique($parentIDs); > > > > foreach ($parentIDs as $parentID) { > > > if (!empty($parentID)) { > > > $options['id'] = $parentID; > > > $this->reorder($options); > > > } > > > } > > > } > > > > Is this a good way of approaching it? The most obvious problem I can > > > see at the moment is that the top level still isn't getting > > > alphabetised, and I'm not sure how to do this. I'm also still not > > > sure ifreorder() recurses as far as it can, or just one level. > > > > Thanks for any help or suggestions! > > > > Zoe. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
