请高人指正
TagLib/TagLibFront.class./**
* @author Meik
* @homepage http://www.xuzc.cn
* @filename TagLibFront.class. * @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 = ' $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 .= '$' . $result . '){ ?>';
$parseStr .= ' $parseStr .= $content;
$parseStr .= ' return $parseStr;
}

}用法 :任意模板文件

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

09-05 14:57