Tree Behavior: how to quickly reorder existing data over a specific field?

I have a cakephp application with a category model that acts like a tree. I imported ~ 100 categories via csv file.

I want to be able to quickly reorder all categories by name in order to order my index index.

I tried a method reorderfrom tree behavior :

$this->Category->reorder(array(
'id' => null,
'field' => 'Category.name',
'order' => 'ASC'
));

But he does nothing. Did I miss something?

Thank:)

+3
source share
3 answers

, generatetreelist() - , , node. - "threaded", SQL-, . :

public function getThreaded($conditions = array()) {
    return $this->find('threaded', array(
        'order' => 'Category.name ASC',
        'contain' => false
    ));
}

, "", , ! contain => false ( node, ), , .

, 100% , generatetreelist(), , , , . generatetreelist(), :

$treeArray = array();
foreach($category as $parent) {
    $treeArray[] = $parent['Category']['name'];
    if(!empty($parent['children']) {
        foreach($parent['children'] as $childCategory) {
            $treeArray[] = ' - '.$childCategory['Category']['name'];
        }
    }
}

, .

+4

: reorder() , MPTT ( , ). find() , reorder(). order find(), .

, , TreeBehavior: lft left rght . reorder(), , , - :

$this->Category->find('all', array(
    'order' => array(
        'Category.lft' => 'ASC'
    )
));

, find, - , 'all'.

Category.lft , , - , , order 'order' => 'Category.name' find, .

P.S.: , 2 , , reorder(), , .

+4

If you use the TreeLi helper to convert the generateTreeList results to a UL / LI list, you can use the jQuery TinySort plugin to sort the tree ( http://tinysort.sjeiti.com/ ).

+1
source

All Articles