来源:http://trac.seagullproject.org/wiki/Howto/Navigation/ModifyingCategoryMenu
======如何修改category菜单块======
=====结构=====
Category菜单块中(例如:CategoryNav.php或ShopNav.php),你可以定义导航块的外观. 代码执行如下:
setStartId(0);
$html = '
';
$html .= $menu->toHtml();
return $html;
}
?>
目前通过为menu builder生成一个新的类,可以修改外观.
将block中的这行
"$menu = & new MenuBuilder('ExplorerBsd');"
修改成
"$menu = & new MenuBuilder('Example');"
接着,在102行中,将这个类添加到modules/navigation/classes/MenuBuilder.php中.
GUI->render($this->_startId);
break;
?>
=====自定义Menu Builder=====
不要小看最后一步哦,你必须创建属于自己的菜单创建者类modules/navigation/classes/menu/Example.php,在这个类中你可以指定categories的外观:
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
$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();"时,你可以给这个类传递一些选项.
* images - 图片文件夹的路径.默认是"images".
* linkTarget - 链接的标签,默认是"_self"
* defaultClass - 应用于一个结点的默认的CSS类,默认是执行的.
* usePersistence - 是否使用客户端的延续.使用cookies来完成这个延续.默认是true.
* noTopLevelImages - 如果有多个顶级分枝时,是否跳过显示第一级的图片.还有一个布尔值是,整个树是否是动态的.这不考虑任一个结点的动态设置.