欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

一直在用的模板数据调用标签

程序员文章站 2022-06-15 18:06:34
...
请高人指正
TagLib/TagLibFront.class.php/**
* @author Meik
* @homepage http://www.xuzc.cn
* @filename TagLibFront.class.php
* @encoding UTF-8
* @datetime 2011-6-27 14:59:38
* @version 1.0
* @Description
*/
class TagLibFront extends TagLib {

protected $tags = array(
'list' => array('attr' => 'table,where,order,limit,relation,field,result,page,purl,purlvars', 'close' => 1),
);

//获取列表数据 可关联(字段过滤无效) 可分页
public function _list($attr, $content) {
$tag = $this->parseXmlAttr($attr, 'list');
$result = !empty($tag['result']) ? $tag['result'] : 'data';
if (!empty($tag['table'])) {
$model = 'D("' . $tag['table'] . '")';
} else {
return '';
}
$key = !empty($tag['key']) ? $tag['key'] : 'i';
$mod = isset($tag['mod']) ? $tag['mod'] : '2';
//拼接SQL查询语句
$parseStr = ' if($tag['where']!= null && $tag['where']=='$where') {
$parseStr .=$tag['where'] != null ? '$map='.$tag["where"].';' : '';
}else {
$parseStr .=$tag['where'] != null ? '$map=array(' . trim(str_replace("=", "=>", $tag["where"]),',') . ');' : '';
}

if ($tag["page"]) {
$parseStr .= '$' . $result . '_count=' . $model;
$parseStr .= $tag['where'] != null ? '->where($map)' : '';
$parseStr .='->cache(true)->count(' . $model . '->getPk());';
$parseStr .= 'import("ORG.Util.Page"); $' . $result . '_p = new Page($' . $result . '_count, ' . $tag["page"] . ');';
if($tag['purlvars']!=null) {
$parseStr .= '$' . $result . '_page = $' . $result . '_p->show("'.$tag['purl'].'",'.$tag['purlvars'].');';
}else {
$parseStr .= '$' . $result . '_page = $' . $result . '_p->show("'.$tag['purl'].'");';
}
}
$parseStr .= '$' . $result . '_result = ' . $model ;
$parseStr .= $tag['relation'] != null ? '->relation(array(' . trim($tag["relation"],',') . '))' : '';
$parseStr .= $tag['where'] != null ? '->where($map)' : '';
$parseStr .= $tag['field'] != null ? '->field("'.trim($tag["field"],',').'")' : '';
$parseStr .= $tag['order'] != null ? '->order("'.trim($tag["order"],',').'")' : '';
if ($tag["page"]) {
$parseStr .= $tag['page'] != null ? '->limit("$' . $result . '_p->firstRow , $' . $result . '_p->listRows")' : '';
}else {
$parseStr .= $tag['limit'] != null ? '->limit("'.trim($tag["limit"],',').'")' : '';
}
$parseStr .= '->select();?>';
$parseStr .= ' $parseStr .= 'foreach($' . $result . '_result as $key=>$' . $result . '){ ?>';
$parseStr .= '';
$parseStr .= $content;
$parseStr .= '';
return $parseStr;
}

}
用法 :任意模板文件
  • ·{$data.bt}

  • AD:真正免费,域名+虚机+企业邮箱=0元