|
来源:http://trac.seagullproject.org/wiki/Howto/Navigation/WorkingWithCategories 使用category这个教程是关于如何将category功能添加到模块中。 开始
o 进入 Publisher -> Categories -> Add new Root Category
o 添加 Category:输入Category名和权限(基于角色)
o 记下新建导航标签的id,
o 你可以从CategoryNav?.php复制
o 重新命名类属性
o 在getBlockContent()中将新的ID添加到$menu->setStartId()
o 在ModuleMgr类validate()中添加: $input->javascriptSrc = array('TreeMenu.js');
这样带有category树的block应该就可见了。category block会自动处理将适当的参数添加到URL上。 SQL在你模块的表表内添加一个 'category_id': ALTER TABLE `event` ADD `category_id` INT( 11 ) NOT NULL AFTER `event_id` ; 这便是在数据库方面你所需要做的修改,因为Seagull会处理嵌套结构。 不要忘了重建Data Objects! 你模块中的代码想要在模块中使用category分类,你必须包含 /navigation/classes/CategoryMgr.php: require_once SGL_MOD_DIR.'/navigation/classes/CategoryMgr.php'; _validation()获取当前的category类别 $input->currentCat = (int)$req->get('frmCatID');
生成select列表框我创建了一个函数用来返回子类数组: function _generateCategoryArray($rootCatId)
{
$menu1 = & new MenuBuilder('SelectBox');
$menu1->setStartId($rootCatId);
$aHtmlOptions = $menu1->toHtml();
return $aHtmlOptions;
}
在add方法中添加: $output->aCategories = $this->_generateCategoryArray($rootCatId); 在edit方法中添加: $output->aCategories = $this->_generateCategoryArray($rootCatId); $output->currentCat = $event->category_id; $event是模块的数据对象。 在模板中: <select name="event[category_id]">{generateSelect(aCategories,currentCat):h}</select>
Breadcrumbs (you are here:)$menu = & new MenuBuilder('SelectBox');
$output->breadCrumbs = $menu->getBreadCrumbs($input->currentCat);
在模板中: <strong>{translate(#You are here#)}:</strong> {breadCrumbs:h}
|