Joomla!-开源天空

2008-12-05
首页 专栏热点 Joomla! 源代码分析 中文自动标签生成Joomla!扩展制作教程(七)-com_tags管理后台分页


中文自动标签生成Joomla!扩展制作教程(七)-com_tags管理后台分页

E-mail

随着标签越来越多,在组件后台管理的时候有点麻烦,因此需要给后台分页。所涉及的文件包括后台的view.html.php,tmpl/default.php和models/tagss.php,其中最多改动是models/tagss.php,其主要代码如下:


class TagssModelTagss extends JModel
{
 var $_data;
 function __construct()
 {
  parent::__construct();
  global $mainframe, $option;
  $limit  = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
  $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
  $this->setState('limit', $limit);
  $this->setState('limitstart', $limitstart);
 }
 function _buildQuery()
 {
  $query = ' SELECT *  FROM #__tags';
  return $query;
 }
 function getData()
 {
  // Lets load the content if it doesn't already exist
  if (empty($this->_data))
  {
   $query = $this->_buildQuery();
   $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
  }
  return $this->_data;
 }
 function getTotal()
 {
  // Lets load the content if it doesn't already exist
  if (empty($this->_total))
  {
   $query = $this->_buildQuery();
   $this->_total = $this->_getListCount($query);
  }
  return $this->_total;
 }
 
 function getPagination()
 {
  // Lets load the content if it doesn't already exist
  if (empty($this->_pagination))
  {
   jimport('joomla.html.pagination');
   $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
  }
  return $this->_pagination;
 } 
}

我们可以看到多了一个构造函数,主要是取得$limit和$limitstart变量。另外主要是多了getTotal函数和getPagination,我们可以看到分页对象也在models中得到了,这跟我们以前分页对象通常在view.html.php中取得略有不同。

我们对于default.php的修改,主要是增加了:

<?php echo $this->pagination->getListFooter();?>

我们看到使用的getListFooter(),如果使用常用getPagelinks,会出现JS脚本错误而无法分页。


现在的效果如下:

 

Attatchments:
您还没有登录,登录后方能下载,如果您还没有注册,请点击 免费注册
相关文章:
中文tags cloud Joomla! 组件发布
中文自动标签生成Joomla!扩展制作教程(九)-tags cloud 模块完整版
中文自动标签生成Joomla!扩展制作教程(八)-tags cloud 模块
简体中文标签自动生成Joomla!组件,插件,标签云模块
中文自动标签生成Joomla!扩展制作教程(六)-自动生成文章标签
中文自动标签生成Joomla!扩展制作教程(五)-增加组件列表功能
中文自动标签生成Joomla!扩展制作教程(四)-创建插件
中文自动标签生成Joomla!扩展制作教程(三)-增加组件的tags生产功能
中文自动标签生成Joomla!扩展制作教程(二)-创建组件框架
中文自动标签生成Joomla!扩展制作教程(一)-前言


收藏此文章:
Digg! Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码