Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just a reminder: the <code>reorder()</code> method from the Tree behavior only modifies the <strong>left</strong> and <strong>right</strong> fields of a tree following <a href="http://www.sitepoint.com/hierarchical-data-database-2/" rel="nofollow">MPTT logic</a> (which is the type of tree used by this behavior). It does not make all <code>find()</code> in that model magically deliver the order defined by your <code>reorder()</code> method. You still need to pass an <code>order</code> parameter in the <code>find()</code> options to actually use the updated left and right values.</p> <p>Suppose you are using the default column names used by TreeBehavior: <code>lft</code> for the <strong>left</strong> field and <code>rght</code> for the <strong>right</strong> field. After running once the <code>reorder()</code> method given in the question, to get the ordered data from your Model to pass to your View, you would use something like:</p> <pre><code>$this-&gt;Category-&gt;find('all', array( 'order' =&gt; array( 'Category.lft' =&gt; 'ASC' ) )); </code></pre> <p>Of course replacing the <code>find</code> type if you want to use something else than <code>'all'</code>.</p> <p>Ordering by <code>Category.lft</code> will in fact show you the order you would get by making a depth-first search, left to right - not an arbitrary order defined by the database like would happen if you had no <code>order</code> parameter, or if you used a simple <code>'order' =&gt; 'Category.name'</code> in the <code>find</code> options which would ignore the tree structure.</p> <p>P.S.: I know the question is 2 years old, but since nobody else explained what <code>reorder()</code> <em>actually</em> does, I think this would be useful.</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.
    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