Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have just been looking into this and have come to the conclusion it is not possible to order the results in the <code>generatetreelist()</code> method - at least no easy way without looping through and manually moving each node. The best way to go about this is use the normal find method with the first argument as 'threaded', then you can apply SQL ordering like you would any query. I have this method in my Category model:</p> <pre><code>public function getThreaded($conditions = array()) { return $this-&gt;find('threaded', array( 'order' =&gt; 'Category.name ASC', 'contain' =&gt; false )); } </code></pre> <p>This returns me an array of all my parent categories alphabetically-ordered, with a 'children' key containing another array all the children of that category, in alphabetical order too! I use <code>contain =&gt; false</code> to cut down on the data returned (threaded returns data about each node's parent, which we don't need to know), you could alter it to include extra data if need be. </p> <p>I understand this isn't 100% the same as <code>generatetreelist()</code>, but it's certainly tidier and a lot more flexible as you control the output. If you really needed to emulate <code>generatetreelist()</code>'s behavior, you could just loop through the array from above like so:</p> <pre><code>$treeArray = array(); foreach($category as $parent) { $treeArray[] = $parent['Category']['name']; if(!empty($parent['children']) { foreach($parent['children'] as $childCategory) { $treeArray[] = ' - '.$childCategory['Category']['name']; } } } </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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