예제 #1
0
  PRIMARY KEY  (`lockID`,`lockTable`)
) TYPE=MyISAM COMMENT='Table locks for comments';
*/
// }}}
// {{{ set up variables
require_once 'DB/NestedSet.php';
require_once 'DB/NestedSet/Output.php';
$dsn = 'mysql://*****:*****@localhost/test';
$params = array('id' => 'id', 'parent_id' => 'rootid', 'left_id' => 'l', 'right_id' => 'r', 'order_num' => 'norder', 'level' => 'level', 'name' => 'name');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
// we want the nodes to be displayed ordered by name, so we add the secondarySort attribute
$nestedSet->setAttr(array('node_table' => 'nested_set', 'lock_table' => 'nested_set_locks', 'secondarySort' => 'name'));
// get data (important to fetch it as an array, using the true flag)
$data = $nestedSet->getAllNodes(true);
// }}}
// {{{ manipulate data
// add links to each item
foreach ($data as $id => $node) {
    $data[$id]['link'] = 'http://example.com/foo.php?' . $node['id'];
}
// }}}
// {{{ render output
$params = array('structure' => $data, 'textField' => 'name', 'linkField' => 'link');
$output =& DB_NestedSet_Output::factory($params, 'TreeMenu');
$output->printListbox();
// }}}
?>
</div>
</body>
</html>
예제 #2
0
require_once 'DB/NestedSet/Output.php';
// Choose a database abstraction layer. 'DB' and 'MDB' are supported.
$nese_driver = 'DB';
// Set the DSN - see http://pear.php.net/manual/en/core.db.tut_dsn.php for details
$nese_dsn = 'mysql://*****:*****@localhost/test';
// Specify the database columns which will be used to specify a node
// Use an associative array. On the left side write down the name of the column.
// On the right side write down how the property will be called in a node object
// Some params are needed
$nese_params = array("STRID" => "id", "ROOTID" => "rootid", "l" => "l", "r" => "r", "STREH" => "norder", "LEVEL" => "level", "STRNA" => "name", "STLNK" => "link");
// Now create an instance of DB_NestedSet
$NeSe =& DB_NestedSet::factory($nese_driver, $nese_dsn, $nese_params);
if (PEAR::isError($NeSe)) {
    echo $NeSe->getCode() . ": " . $NeSe->getMessage();
}
// Fetch the tree as array
$nodes = $NeSe->getAllNodes(true);
// Set the basic params
$params = array('structure' => $nodes, 'options' => array(), 'textField' => 'name', 'linkField' => 'link', 'currentLevel' => 1);
// This array contains the options needed
// for printing out the menu.
$options = array('rootStyles' => array('onmouseout' => array('color' => '#FF0000', 'background' => '#000000', 'textDecoration' => 'none', 'border' => "1px solid #FFFFFF", 'fontSize' => '11px', 'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif', 'fontWeight' => 'bold', 'textAlign' => 'center', 'padding' => '2px'), 'onmouseover' => array('color' => '#FFFFFF', 'background' => '#000000', 'textDecoration' => 'none'), 'onmousedown' => array('color' => '#FFFFFF', 'background' => '#000000', 'textDecoration' => 'none')), 'childStyles' => array('onmouseout' => array('color' => '#000000', 'background' => '#CCCCCC', 'textDecoration' => 'none', 'border' => "1px solid #FFFFFF", 'fontSize' => '11px', 'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif', 'fontWeight' => 'normal', 'textAlign' => 'left', 'padding' => '2px'), 'onmouseover' => array('color' => '#FFFFFF', 'background' => '#EEEEEE', 'textDecoration' => 'none'), 'onmousedown' => array('color' => '#FFFFFF', 'background' => '#EEEEEE', 'textDecoration' => 'none')), 'rootGeometry' => array('width' => '120', 'height' => '21', 'left' => '119', 'top' => '0', 'block_left' => '169', 'block_top' => '121', 'hide_delay' => '200'), 'childGeometry' => array('width' => '*6', 'height' => '21', 'left' => '0', 'top' => '20', 'block_left' => '0,-5', 'block_top' => '20,10', 'hide_delay' => '2000'), 'menu_id' => 1);
// Now create the menu object, set the options and do the output
$menu =& DB_NestedSet_Output::factory($params, 'TigraMenu');
$menu->setOptions('printTree', $options);
$menu->printTree();
// Have fun!
?>