I'm currently working on releasing a hierarchy in terms of the navigation menu from nestedSet to Doctrine.
I have several parents who have several children.
Currently, there are only 2 levels: Parent and Child (no grandchildren).
I have the following code:
//actions: public function executeShow(sfWebRequest $request) { $this->tree = Doctrine::getTable('Model')->getMenuTree(); } //lib: class ModelTable extends Doctrine_Table { /** * Gets tree element in one query */ public function getMenuTree() { $q = $this->createQuery('g') ->orderBy('g.root_id') ->addOrderBy('g.lft') ->where('g.root_id NOT NULL'); return $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY_HIERARCHY); } } //template: <?php function echoNode($tree, $parent=null) { ?> <ul> <?php foreach ($tree as $node): ?> <li data-id='<?php echo $node['id'] ?>'> <?php echo $node['name'] ?> <?php if (count($node['__children']) > 0): ?> <?php echo echoNode($node['__children'], $node) ?> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php } ?> <?php echo echoNode($tree) ?>
This outputs:
Parent Node 1 Child Node 1 Child Node 2 Parent Node 2 Child Node 3
It's great.
The problem is that I would like my URLs to match the relationship between parents and children.
So the URL for Child Node 2 will be /parent-node-1/child-node-2 (it's like slug ).
Therefore, any parent child must have parent Node traffic.
I hope this makes sense?
thanks
source share