来源:http://trac.seagullproject.org/wiki/Howto/Navigation/WorkingWithCategories

使用category

这个教程是关于如何将category功能添加到模块中。

开始

  • 注册模块,否则你不能将它添加到导航栏上。
  • 创建一个新的category
        o 进入 Publisher -> Categories -> Add new Root Category
        o 添加 Category:输入Category名和权限(基于角色)
        o 记下新建导航标签的id,
  • 创建子类别
  • 创建navigation block.
        o 你可以从CategoryNav?.php复制
        o 重新命名类属性
        o 在getBlockContent()中将新的ID添加到$menu->setStartId() 
  • 将你的模块添加到导航栏,不然你就不能添加category block
  • 添加category block到你的模块 (navigation point)
  • 添加category block(CategoryNav或者是你的)到页面:
        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}
 
howto/navigation/workingwithcategories.txt · 最后更改: 2010/05/30 00:21 (外部编辑)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2