喜欢就分享给更多人!

dedecms独立模型分页功能的完善

dede教程 03-01 11:41
dedecms独立模型分页功能的完善

dedecms其实在架构方面没什么问题,但是估计里面有些功能是新手做的吧,有很多待完善的地方,比如分页功能,从代码可以直接看出当时的负责人有敷衍了事的心里。

dede的分页如果有两个页码显示的话,无法显示出总的文章数,举个例子:

在普通文章模型下面,列表的分页是这样的:

dedecms独立模型分页功能的完善

但是在独立模型中就成了这样了

dedecms独立模型分页功能的完善

最后面的共*页*条的信息不见了,相信遇到这个问题的同学首先想到的是自己哪里用错了,其实不是,dede独立模型这里的代码是偷工减料了的。处理独立模型列表的代码在arc.sglistview.class.php中,我们比较下同样负责显示分页的代码段,独立模型和普通模型中有什么区别:

普通文章模型:

001/**
002* 获取动态的分页列表
003*
004* @access public
005* @param string $list_len 列表宽度
006* @param string $list_len 列表样式
007* @returnstring
008*/
009functionGetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
010{
011global $cfg_rewrite;
012$prepage = $nextpage = '';
013$prepagenum = $this->PageNo-1;
014$nextpagenum = $this->PageNo+1;
015if($list_len==''|| preg_match("/[^0-9]/", $list_len))
016{
017$list_len=3;
018}
019$totalpage = ceil($this->TotalResult/$this->PageSize);
020if($totalpage<=1 && $this->TotalResult>0)
021{
022return"<li><span class=\"pageinfo\">共 1 页/".$this->TotalResult." 条记录</span></li>\r\n";
023}
024if($this->TotalResult == 0)
025{
026return"<li><span class=\"pageinfo\">共 0 页/".$this->TotalResult." 条记录</span></li>\r\n";
027}
028$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
029$purl = $this->GetCurUrl();
030// 如果开启为静态,则对规则进行替换
031if($cfg_rewrite == 'Y')
032{
033$nowurls = preg_replace("/\-/", ".php?", $purl);
034$nowurls = explode("?", $nowurls);
035$purl = $nowurls[0];
036}
037$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
038$purl .= '?'.$geturl;
039$optionlist = '';
040//$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>\r\n";
041//$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
042//获得上一页和下一页的链接
043if($this->PageNo != 1)
044{
045$prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
046$indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
047}
048else
049{
050$indexpage="<li><a>首页</a></li>\r\n";
051}
052if($this->PageNo!=$totalpage && $totalpage>1)
053{
054$nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
055$endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
056}
057else
058{
059$endpage="<li><a>末页</a></li>\r\n";
060}
061//获得数字链接
062$listdd="";
063$total_list = $list_len * 2 + 1;
064if($this->PageNo >= $total_list)
065{
066$j = $this->PageNo-$list_len;
067$total_list = $this->PageNo+$list_len;
068if($total_list>$totalpage)
069{
070$total_list=$totalpage;
071}
072}
073else
074{
075$j=1;
076if($total_list>$totalpage)
077{
078$total_list=$totalpage;
079}
080}
081for($j;$j<=$total_list;$j++)
082{
083if($j==$this->PageNo)
084{
085$listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
086}
087else
088{
089$listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
090}
091}
092$plist = '';
093if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
094if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
095if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
096if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
097if(preg_match('/end/i', $listitem)) $plist .= $endpage;
098if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
099if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
100if($cfg_rewrite == 'Y')
101{
102$plist = str_replace('.php?tid=', '-', $plist);
103$plist = str_replace('&TotalResult=', '-', $plist);
104$plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
105}
106return$plist;
107}

独立模型:

01/**
02* 获取动态的分页列表
03*
04* @access public
05* @param int $list_len 列表宽度
06* @param string $listitem 列表样式
07* @returnstring
08*/
09functionGetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
10{
11global $nativeplace,$infotype,$keyword;
12if(empty($nativeplace)) $nativeplace = 0;
13if(empty($infotype)) $infotype = 0;
14if(empty($keyword)) $keyword = '';
15$prepage = $nextpage = '';
16$prepagenum = $this->PageNo - 1;
17$nextpagenum = $this->PageNo + 1;
18if($list_len==""|| preg_match("/[^0-9]/", $list_len))
19{
20$list_len=3;
21}
22$totalpage = ceil($this->TotalResult / $this->PageSize);
23if($totalpage<=1 && $this->TotalResult>0)
24{
25return"<span class=\"pageinfo\">共1页/".$this->TotalResult."条记录</span>";
26}
27if($this->TotalResult == 0)
28{
29return"<span class=\"pageinfo\">共0页/".$this->TotalResult."条记录</span>";
30}
31$purl = $this->GetCurUrl();
32$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&";
33$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n";
34$hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n";
35$hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n";
36$hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n";
37$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
38$purl .= "?".$geturl;
39//获得上一页和下一页的链接
40if($this->PageNo != 1)
41{
42$prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
43$indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
44}
45else
46{
47$indexpage="<li><a>首页</a></li>\r\n";
48}
49if($this->PageNo!=$totalpage && $totalpage>1)
50{
51$nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
52$endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
53}
54else
55{
56$endpage="<li><a>末页</a></li>";
57}
58//获得数字链接
59$listdd="";
60$total_list = $list_len * 2 + 1;
61if($this->PageNo >= $total_list)
62{
63$j = $this->PageNo - $list_len;
64$total_list = $this->PageNo + $list_len;
65if($total_list > $totalpage)
66{
67$total_list = $totalpage;
68}
69}
70else
71{
72$j=1;
73if($total_list > $totalpage)
74{
75$total_list = $totalpage;
76}
77}
78for($j; $j <= $total_list; $j++)
79{
80if($j == $this->PageNo)
81{
82$listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
83}
84else
85{
86$listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
87}
88}
89$plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
90return$plist;
91}

仔细观察 普通模型中在28行左右的位置多了句$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";而在独立模型中则没有。

而且在最后,普通模型中将$maininfo的值加入了$plist字符串中。(更细节的地方是普通模型还判断了标签中是否有info属性来决定是否加入:

1if(preg_match('/info/i', $listitem)) $plist .= $maininfo;

)独立模型中这些都省了。

要将独立模型修改过来很简单,不过“普通模型还判断了标签中是否有info属性来决定是否加入”这点我就不去实现了,这里不判断直接再任何情况下都加入maininfo:

查看源码
打印代码帮助
01/**
02* 获取动态的分页列表
03*
04* @access public
05* @param int $list_len 列表宽度
06* @param string $listitem 列表样式
07* @returnstring
08*/
09functionGetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
10{
11global $nativeplace,$infotype,$keyword;
12if(empty($nativeplace)) $nativeplace = 0;
13if(empty($infotype)) $infotype = 0;
14if(empty($keyword)) $keyword = '';
15$prepage = $nextpage = '';
16$prepagenum = $this->PageNo - 1;
17$nextpagenum = $this->PageNo + 1;
18if($list_len==""|| preg_match("/[^0-9]/", $list_len))
19{
20$list_len=3;
21}
22$totalpage = ceil($this->TotalResult / $this->PageSize);
23if($totalpage<=1 && $this->TotalResult>0)
24{
25return"<span class=\"pageinfo\">共1页/".$this->TotalResult."条记录</span>";
26}
27if($this->TotalResult == 0)
28{
29return"<span class=\"pageinfo\">共0页/".$this->TotalResult."条记录</span>";
30}
31$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
32$purl = $this->GetCurUrl();
33$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&";
34$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n";
35$hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n";
36$hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n";
37$hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n";
38$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
39$purl .= "?".$geturl;
40//获得上一页和下一页的链接
41if($this->PageNo != 1)
42{
43$prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
44$indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
45}
46else
47{
48$indexpage="<li><a>首页</a></li>\r\n";
49}
50if($this->PageNo!=$totalpage && $totalpage>1)
51{
52$nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
53$endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
54}
55else
56{
57$endpage="<li><a>末页</a></li>";
58}
59//获得数字链接
60$listdd="";
61$total_list = $list_len * 2 + 1;
62if($this->PageNo >= $total_list)
63{
64$j = $this->PageNo - $list_len;
65$total_list = $this->PageNo + $list_len;
66if($total_list > $totalpage)
67{
68$total_list = $totalpage;
69}
70}
71else
72{
73$j=1;
74if($total_list > $totalpage)
75{
76$total_list = $totalpage;
77}
78}
79for($j; $j <= $total_list; $j++)
80{
81if($j == $this->PageNo)
82{
83$listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
84}
85else
86{
87$listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
88}
89}
90$plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;;
91return$plist;
92}


友情链接: 菜鸟吧源码 菜鸟聚会登录 网站目录大全 菜鸟吧导航网 冒泡网赚 中创网 福缘创业网 臭虾米项目网 小淘学社 吾图资源网 懒人之家源码 ASP300源码 折翼天使 锦尚中国 莎莎源码论坛 吾爱源码论坛 织梦58 搜虎源码论坛 游戏咖啡屋 码农网 虎格网 织梦猫 魔克吧 忽悠兄基地

网站快速入口:| 网站首页 | 用户登录 | 快捷登录 | 注册账号 | 会员中心 |