Note that there are some explanatory texts on larger screens.

plurals
  1. POnestedSet - parent/child nodes
    primarykey
    data
    text
    <p>I am currently working on outputting a heirarchy in terms of a navigation menu from a nestedSet in Doctrine.</p> <p>I have a number of parents that then have several children.</p> <p>At the moment in time, there are only 2 levels: Parent and Child (no grandchildren).</p> <p>I have the following code:</p> <pre><code>//actions: public function executeShow(sfWebRequest $request) { $this-&gt;tree = Doctrine::getTable('Model')-&gt;getMenuTree(); } //lib: class ModelTable extends Doctrine_Table { /** * Gets tree element in one query */ public function getMenuTree() { $q = $this-&gt;createQuery('g') -&gt;orderBy('g.root_id') -&gt;addOrderBy('g.lft') -&gt;where('g.root_id NOT NULL'); return $q-&gt;execute(array(), Doctrine_Core::HYDRATE_ARRAY_HIERARCHY); } } //template: &lt;?php function echoNode($tree, $parent=null) { ?&gt; &lt;ul&gt; &lt;?php foreach ($tree as $node): ?&gt; &lt;li data-id='&lt;?php echo $node['id'] ?&gt;'&gt; &lt;?php echo $node['name'] ?&gt; &lt;?php if (count($node['__children']) &gt; 0): ?&gt; &lt;?php echo echoNode($node['__children'], $node) ?&gt; &lt;?php endif; ?&gt; &lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;?php } ?&gt; &lt;?php echo echoNode($tree) ?&gt; </code></pre> <p>This renders out:</p> <pre><code>Parent Node 1 Child Node 1 Child Node 2 Parent Node 2 Child Node 3 </code></pre> <p>Which is great.</p> <p>The problem is, that I'd like my URLs to match the parent/child relationship.</p> <p>Thus the URL for Child Node 2, would be <code>/parent-node-1/child-node-2</code> (these as <code>slug</code> fields).</p> <p>So any child of a parent, needs to have the parent node's route slug as well.</p> <p>I hope that make sense?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload