id_primary_key
id_parent
sequence
name
...
И стояла задача работать с этой иерархией. Т.к. было несколько таблиц, получилось вполне удобное поведение.
Подключается к модели следующим образом (пример для категорий товаров):
Код: Выделить всё
public function behaviors() {
return array(
'tree' => array(
'class' => 'ActiveRecordTreeBehavior',
'order' => 'id_parent DESC, sequence ASC',
'idParentField' => 'id_parent',
'with' => 'productCount',
),
);
}
Код: Выделить всё
// получаем дерево экземпляров:
$tree = ProductCategory::model()->getTree();
// кол-во корневых элементов:
$count = $tree->getChildCount();
...
getTree()
getParent()
getChildCount()
getChild()
isChildExists()
getChildById($id)
getParentById($id)
isAncestor(CActiveRecord $model)
isDescendant(CActiveRecord $model, $checkSelf = false)
getRootParent()
Может кому пригодится.