One more note, MonkeyGirl, and I'm sure we're already on the same page, but the syntax should be $this->ModelName->reorder(); Using the categories example from http://book.cakephp.org/view/228/Basic-Usage , the syntax to reorder the entire tree by name is $this->Category- >reorder();
On Nov 2, 9:22 pm, Robert P <shiftyrobs...@gmail.com> wrote: > 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 <hayl...@gmail.com> wrote: > > > To be more specific in addressing, "I'm also still not > > sure ifreorder() recurses as far as it can, or just one level. " -- > > Yes, it will recurse thetreeuntil it finds no children in all > > affected branches. > > > On Nov 2, 8:25 pm, Kerr <hayl...@gmail.com> 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 <z...@monkeehouse.com> 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---