<?php
import('TagLib');
class TagLibXl extends TagLib{
protected $tags=array(
'list'=>array(
'attr'=>'table,limit', //设置标签属性
'level'=>'3', //循环次数
'close'=>'1', //是否闭合
),
);
function _list($attr,$content){
$tag=$this->parseXmlAttr($attr, 'list'); //解析操作,TP的自定义标签是基于xml的
$db=M($tag['table']); //根据返回的table值实例化
$list=$db->limit($tag['limit'])->select(); //查询返回数据
preg_match_all("/\[field\:\w*\]/",$content,$match); //获取返回值里[field:xxx]这种格式
$match=$match[0];
$match=array_unique($match);//去掉数组重复项
foreach($match as $i=>$vo){
$field[$i]=substr($vo,7,count($vo)-2);
}
//以下循环为遍历将[field:xxx]格式替换为实际内容
foreach($list as $i=>$value){
if($i==0){
$parseStr=$content;
}else{
$parseStr=$parseStr.$content;
}
foreach($match as $j=>$vo){
$parseStr=str_replace($vo,$value[$field[$j]],$parseStr);
}
}
//解析内容模板,并返回字符串
if(!empty($parseStr)) {
return $this->tpl->parse($parseStr);
}
return ;
}
}
?>现在不知道如何写分页的标签?有没有详细点的教程或手册呢 最佳答案