请高人指正
TagLib/TagLibFront.class.php/**<br>
* @author Meik<br>
* @homepage http://www.xuzc.cn<br>
* @filename TagLibFront.class.php<br>
* @encoding UTF-8<br>
* @datetime 2011-6-27 14:59:38<br>
* @version 1.0<br>
* @Description<br>
*/<br>
class TagLibFront extends TagLib {<br>
<br>
protected $tags = array(<br>
'list' => array('attr' => 'table,where,order,limit,relation,field,result,page,purl,purlvars', 'close' => 1),<br>
);<br>
<br>
//获取列表数据 可关联(字段过滤无效) 可分页<br>
public function _list($attr, $content) {<br>
$tag = $this->parseXmlAttr($attr, 'list');<br>
$result = !empty($tag['result']) ? $tag['result'] : 'data';<br>
if (!empty($tag['table'])) {<br>
$model = 'D("' . $tag['table'] . '")';<br>
} else {<br>
return '';<br>
}<br>
$key = !empty($tag['key']) ? $tag['key'] : 'i';<br>
$mod = isset($tag['mod']) ? $tag['mod'] : '2';<br>
//拼接SQL查询语句<br>
$parseStr = '<?php ';<br />
if($tag['where']!= null && $tag['where']=='$where') {<br>
$parseStr .=$tag['where'] != null ? '$map='.$tag["where"].';' : '';<br>
}else {<br>
$parseStr .=$tag['where'] != null ? '$map=array(' . trim(str_replace("=", "=>", $tag["where"]),',') . ');' : '';<br>
}<br>
<br>
if ($tag["page"]) {<br>
$parseStr .= '$' . $result . '_count=' . $model;<br>
$parseStr .= $tag['where'] != null ? '->where($map)' : '';<br>
$parseStr .='->cache(true)->count(' . $model . '->getPk());';<br>
$parseStr .= 'import("ORG.Util.Page"); $' . $result . '_p = new Page($' . $result . '_count, ' . $tag["page"] . ');';<br>
if($tag['purlvars']!=null) {<br>
$parseStr .= '$' . $result . '_page = $' . $result . '_p->show("'.$tag['purl'].'",'.$tag['purlvars'].');';<br>
}else {<br>
$parseStr .= '$' . $result . '_page = $' . $result . '_p->show("'.$tag['purl'].'");';<br>
}<br>
}<br>
$parseStr .= '$' . $result . '_result = ' . $model ;<br>
$parseStr .= $tag['relation'] != null ? '->relation(array(' . trim($tag["relation"],',') . '))' : '';<br>
$parseStr .= $tag['where'] != null ? '->where($map)' : '';<br>
$parseStr .= $tag['field'] != null ? '->field("'.trim($tag["field"],',').'")' : '';<br>
$parseStr .= $tag['order'] != null ? '->order("'.trim($tag["order"],',').'")' : '';<br>
if ($tag["page"]) {<br>
$parseStr .= $tag['page'] != null ? '->limit("$' . $result . '_p->firstRow , $' . $result . '_p->listRows")' : '';<br>
}else {<br>
$parseStr .= $tag['limit'] != null ? '->limit("'.trim($tag["limit"],',').'")' : '';<br>
}<br>
$parseStr .= '->select();?>';<br>
$parseStr .= '<?php if($' . $result . '_result){ $' . $key . '=0;';<br />
$parseStr .= 'foreach($' . $result . '_result as $key=>$' . $result . '){ ?>';<br>
$parseStr .= '<?php ++$' . $key . ';$mod = ($' . $key . ' % ' . $mod . ');?>';<br>
$parseStr .= $content;<br>
$parseStr .= '<?php }};?>';<br>
return $parseStr;<br>
}<br>
<br>
}
用法 :任意模板文件<list><br>
<li><a>$data[id]))}">·{$data.bt}</a></li>
<br>
</list>
AD:真正免费,域名+虚机+企业邮箱=0元