|
来源:http://trac.seagullproject.org/wiki/Howto/Navigation/ModifyingCategoryMenu 如何修改category菜单块结构Category菜单块中(例如:CategoryNav.php或ShopNav.php),你可以定义导航块的外观. 代码执行如下: <?php function getBlockContent() { SGL::logMessage(null, PEAR_LOG_DEBUG); $theme = $_SESSION['aPrefs']['theme']; require_once SGL_MOD_DIR . '/navigation/classes/MenuBuilder.php'; $menu = & new MenuBuilder('ExplorerBsd'); $menu->setStartId(0); $html = '<img src="' . SGL_BASE_URL . '/themes/' . $theme . '/images/pixel.gif" width="165" height="1" alt="" /><br />'; $html .= $menu->toHtml(); return $html; } ?> 目前通过为menu builder生成一个新的类,可以修改外观. 将block中的这行 "$menu = & new MenuBuilder('ExplorerBsd');"
修改成 "$menu = & new MenuBuilder('Example');"
接着,在102行中,将这个类添加到modules/navigation/classes/MenuBuilder.php中. <?php case 'menu_explorerbsd': case 'menu_example': $ret = $this->GUI->render($this->_startId); break; ?> 自定义Menu Builder不要小看最后一步哦,你必须创建属于自己的菜单创建者类modules/navigation/classes/menu/Example.php,在这个类中你可以指定categories的外观: <?php class Menu_Example { var $module = 'navigation'; function Menu_Example($options, $conf) { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->conf = $conf; } function render($id = 0) { $menu = $this->getGuruTree($id); $html = $menu->printMenu(); return $html; } function getGuruTree($id = 0) { SGL::logMessage(null, PEAR_LOG_DEBUG); // style definition .treeMenuDefault in <head> $tree = &$this->createFromSQL($id); // initialise the class options require_once 'HTML/TreeMenu.php'; // build url for current page $req = & SGL_Request::singleton(); $url = SGL_Url::makeLink( '', $req->get('managerName'), $req->get('moduleName') ); $url .= 'frmCatID/'; $nodeOptions = array( 'text' => '', 'link' => $url, 'icon' => 'exampleFolder.gif', 'expandedIcon' => 'exampleExpandedFolder.gif', 'class' => '', 'expanded' => false, 'linkTarget' => '_self', 'isDynamic' => 'true', 'ensureVisible' => '', ); $options = array( 'structure' => $tree, 'type' => 'heyes', 'nodeOptions' => $nodeOptions); $menu = HTML_TreeMenu::createFromStructure($options); require_once SGL_MOD_DIR . '/navigation/classes/HTML_TreeMenu_DHTML_SGL.php'; $theme = $_SESSION['aPrefs']['theme']; $treeMenu = & new HTML_TreeMenu_DHTML_SGL($menu, array( 'images' => SGL_BASE_URL . "/themes/$theme/images/imagesAlt2", 'defaultClass' => 'treeMenuDefault', 'noTopLevelImages' => 'true', )); return $treeMenu; } /** * This method imports a tree from a database using the common * id/parent_id method of storing the structure. * */ function &createFromSQL($id = 0) { SGL::logMessage(null, PEAR_LOG_DEBUG); require_once 'HTML/Tree.php'; $dbh = &SGL_DB::singleton(); $query = ' SELECT category_id as id, parent_id, label AS text FROM ' . $this->conf['table']['category'] .' ORDER BY parent_id, order_id'; $tree = &new Tree(); $nodeList = array(); // Perform query $result = $dbh->query($query); if (!PEAR::isError($result)) { while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { // Parent id is 0, thus root node. if (!$row['parent_id']) { unset($row['parent_id']); $nodeList[$row['id']] = &new Tree_Node($row); $tree->nodes->addNode($nodeList[$row['id']]); // Parent node has already been added to tree } elseif (!empty($nodeList[$row['parent_id']])) { $parentNode = &$nodeList[$row['parent_id']]; unset($row['parent_id']); $nodeList[$row['id']] = &new Tree_Node($row); $parentNode->nodes->addNode($nodeList[$row['id']]); } else { // Orphan node ? } } } else SGL::raiseError('problem with getGuruTree query'); // jump into the cat tree at a predefined depth // if $id = 0 return the hole tree OR if $id != 0 return from $id branch $result = ($id) ? $nodeList[$id] : $tree; return $result; } } ?> 这些只是对ExplorerBSD menu builder做轻微的修改.当然你可以添加任何你想的东西. 选项当调用”$treeMenu = & new HTML_TreeMenu_DHTML_SGL();”时,你可以给这个类传递一些选项.
|