1. dodaj do tabeli trzy pola: lft, rgt oraz scope i pozakladaj na nie indeksy
2. jak uzywasz propela to jest funkcja cli to zgrania struktury istniejacej juz bazy i pozmieniaj pola tabeli kategori tak jak to jest napisane na stronie
http://propel.phpdb.org/trac/wiki/Users/Do.../Tree/NestedSet(kolumny lft, rgt oraz scope oraz treeMode odpowiedni)
<table name="menu" idMethod="native" treeMode="NestedSet">
<column name="id" type="INTEGER" required="true" autoIncrement="true" primaryKey="true"/>
<column name="lft" type="INTEGER" required="true" default="0" nestedSetLeftKey="true"/>
<column name="rgt" type="INTEGER" required="true" default="0" nestedSetRightKey="true"/>
<column name="scope" type="INTEGER" required="true" default="0" treeScopeKey="true"/>
<column name="text" type="VARCHAR" size="128" required="true" default=""/>
<column name="link" type="VARCHAR" size="255" required="true" default=""/>
<index name="lft">
<index-column name="lft"/>
</index>
<index name="rgt">
<index-column name="rgt"/>
</index>
<index name="scope">
<index-column name="scope"/>
</index>
</table>
3. wygeneruj sobie model, formularze i co ci tam potrzeba
4. Przykladowe klasy komponentu do wyswietlenia drzewka kategorii (domysle tylko 1 poziom zagniezdzenie a po kliknieciu pokazanie dzieci itd)
<?php
class categoriesComponents extends sfComponents {
public $cat_tree=array();
public function executeList() {
$root = JmdataCategoriesPeer::retrieveTree(1);
$this->it=new myMenuOutput($root);
if ($this->getModuleName() == 'categories' && $this->request->getParameter('id')) {
$this->node=JmdataCategoriesPeer::getNode($this->request->getParameter('id'));
$this->node_path=JmdataCategoriesPeer::getPath($this->node);
$root=JmdataCategoriesPeer::retrieveRoot(1);
$this->getPath($root);
$this->tree=$this->cat_tree;
}
}
private function getPath($root_node) {
foreach ($root_node->getChildren() as $node) {
if (!$this->checkPath($node) && $node->getLevel() == 1) {
$this->cat_tree[]=array('name'=>$node->getName(), 'id'=>$node->getId(),'level'=>$node->getLevel()); } else {
$this->cat_tree[]=array('name'=>$node->getName(), 'id'=>$node->getId(),'level'=>$node->getLevel()); $this->getPath($node);
}
}
}
private function checkPath($node) {
foreach ($this->node_path as $child)
if ($child->getId() == $node->getId())
return true;
return false;
}
}
?>
template:
<div id="adminMenu">
<h4><a href="">.::Kategorie::.</a></h4>
<ul>
<?php if (!$sf_request->hasParameter('id')): ?>
<?php foreach($it as $m): ?>
<?php if ($m->getLevel() == 1): ?>
<li style="padding-left:
<?php echo $m->getLevel() ?>em;">
<?php echo link_to
( $m->getName(),'categories/show?id='.$m->getId()) ?> </li>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php foreach ($tree as $nodes): ?>
<li style="padding-left:
<?php echo $nodes['level']-1 ?>em;">
<?php echo link_to
( $nodes['name'],'categories/show?id='.$nodes['id']) ?> </li>
<?php endforeach ?>
<?php endif; ?>
</ul>
</div>
Kod klasy myMenuOutput:
<?php
class myMenuOutput extends RecursiveIteratorIterator {
function __construct(JmdataCategories $m) {
parent::__construct($m, self::SELF_FIRST);
}
function beginChildren() {
}
function endChildren() {
}
}
?>