Still wrestling with this issue. Managed to contact the author of the script and they re-wrote it a bit, but still no joy for me. See comments here: http://othy.wordpress.com/2006/06/03/generatenestedlist/
The generateNestedList() function just produces an empty variable. I did notice in debug mode that I'm getting an SQL error. Some how the function is trying to query the database with the string 'generateNestedList'. Just to re-cap what I've got in my app: --In the app controller file I've got the snippet from othy which includes the generateNestedList() function - http://othy.wordpress.com/2006/06/03/generatenestedlist/ --In my Model I've just got: class Node extends AppModel { var $name = 'Node'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'NodeType' => array('className' => 'NodeType', 'foreignKey' => 'node_type_id', 'counterCache' => '' ), ); } --In my Controller (for the edit function) I've got: function edit($id = null) { if(empty($this->data)) { if(!$id) { $this->Session->setFlash('Invalid id for Node'); $this->redirect('/nodes/index'); } $this->data = $this->Node->read(null, $id); $this->set('nodeTypes', $this->Node->NodeType->generateList()); $this->set('category_tree', $this->Node->generateNestedList()); // <--this is the line in question } else { $this->cleanUpFields(); if($this->Node->save($this->data)) { $this->Session->setFlash('The Node has been saved'); $this->redirect('/nodes/index'); } else { $this->Session->setFlash('Please correct errors below.'); $this->set('nodeTypes', $this->Node->NodeType->generateList()); } } } --And in my view I've got: <?php echo $form->labelTag('Node/parent_id', 'Parent Id');?> <?php echo $html->selectTag('Node/parent_id', $category_tree, $html- >tagValue('Node/parent_id'), array(), array(), true) --My Nodes DB schema looks like this: http://housepimp.com/cake_nodes.gif Any help would be much appreciated. Thanks, Brett. On Mar 12, 8:26 pm, "double07" <[EMAIL PROTECTED]> wrote: > Using this in the controller: $this->set('category_tree', > $category_tree); > > Just produces this error: Undefined variable: category_tree in C:\wamp > \www\cake\app\controllers\nodes_controller.php on line 47 > > I think this is correct: $this->set('category_tree', > $this->Node->generateNestedList('--', > > null)); > > I have a similar bit of code in the same controller which seems to > work: > $this->set('nodeTypes', $this->Node->NodeType->generateList()); // in > the controller > > <?php echo $html->selectTag('Node/node_type_id', $nodeTypes, > $html->tagValue('Node/node_type_id'), array(), array(), true);?> // in the > > view > > The problem seems specific to the generateNestedList function, I just > can't work it out. The snippet from Othy is just to advanced for a > poor designer to understand ;( > > Cheers, > > Brett. > > On Mar 12, 8:16 pm, "Eric C Blount" <[EMAIL PROTECTED]> wrote: > > > $this->set('category_tree', $category_tree); //in the controller, so the > > view can use the variable... > > > HTH, > > Eric > > > On 3/11/07, double07 <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > I just wanted to re-visit this again. I've come back after a couple of > > > weeks break to attempt to finish this project, in particular the > > > 'parent' select list which needs to be indented (for ease of use). Now > > > I found what I thought was the perfect bit of code by 'Othy' here: > > >http://othy.wordpress.com/2006/06/03/generatenestedlist/ > > > > It's supposed to generate nested lists for use with select/drop downs. > > > It's a bit light on the documentation and I'm having trouble getting > > > it to work. > > > > As per the instructions, in my app_controller.php file I put the > > > following code: > > > > function generateNestedList($indent = ' ',$sort = null) > > > { > > > $this->recursive = '-1'; > > > $cats = $this->findAllThreaded(null, > > > array($this->name.'.id',$this- > > > >name.'.name',$this->name.'.parent_id'), $sort); > > > $glist = $this->_generateNestedList($cats,$indent); return > > > $glist; > > > } > > > function _generateNestedList($cats,$indent,$level = 0) > > > { > > > static $list = array(); > > > for($i = 0, $c = count($cats); $i < $c; $i++) > > > { > > > $list[$cats[$i][$this->name]['id']] = > > > str_repeat($indent,$level). > > > $cats[$i][$this->name]['name']; if(isset($cats[$i]['children']) && ! > > > empty($cats[$i]['children'])) > > > { > > > > $this->_generateNestedList($cats[$i]['children'],$indent,$level + > > > 1); > > > } > > > } > > > return $list; > > > } > > > > Now in my controller (called Nodes) I've got: > > > > $this->set('category_tree', $this->Node->generateNestedList('--', > > > null)); > > > > This seems correct and doesn't produce any errors, however when I try > > > to use the category_tree in a selectTag in my view, I get nothing: > > > > <?php echo $html->selectTag('Node/parent_id', $category_tree, $html- > > > >tagValue('Node/parent_id'), array(), array(), true);?> > > > > If I just print_r $category tree, it's also empty. > > > > Has anybody got experience with this snippet of code by Othy (I'd ask > > > him directly but there doesn't seem to be any contact info on his > > > page)? Or could somebody please give me some pointers??? Alternatively > > > another method would be appreciated. > > > > Thanks again, > > > > Brett. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---