thinkphp中 taglib标签应用

1、配置文件中加上:

'APP_AUTOLOAD_PATH'         =>  '@.TagLib',


2、在项目的/Lib/下新建 TagLib文件夹 复制TagLibHtml.class.php到该目录下面

也可以自己定义格式Tag大驼峰命名.class.php

实例:TagLibCms.class.php代码下面;

3、模版

<tagLib name="html" />

<html:imageBtn name="add" value="新增" />

<cms:article name="content" limit="10" cid="1">
<h1><a href="/{$article.ename}/{$article.id}.html">hhh</a></h1>


</cms:article>



TagLibCms.class.php的代码:

[code]

<?php
import("TagLib");
 
class TagLibCms extends TagLib{
private   $CategoryArr = array();
private   $SubString = '';
protected $tags = array(
'article'=>array('attr'=>'name,field,limit,order,cid,where,sql,key,mod','level'=>3),
);
  
public function _article($attr,$content){
$tag = $this->parseXmlAttr($attr,'article');
$result = !empty($tag['result'])?$tag['result']:'article'; //定义数据查询的结果存放变量
$key = !empty($tag['key'])?$tag['key']:'i';
$mod = isset($tag['mod'])?$tag['mod']:'2';
//print_r($tag['name']);die();
if ($tag['name']){
$sql = "M('{$tag['name']}')->";
$sql .= ($tag['field'])?"field({$tag['field']})->":'';
$sql .= ($tag['order'])?"order({$tag['order']})->":'';
if($tag['cid']){
$cidarr = explode(',',$tag['cid']);
foreach($cidarr AS $k=>$v){
$this->getSubCategory($v);
}
$cidstr = implode(",",$this->SubString);
$tag['where'] = "cid IN(".$cidstr.")";
$sql .= ($tag['where'])?"where(\"{$tag['where']}\")->":'';
}else{
$sql .= ($tag['where'])?"where(\"{$tag['where']}\")->":'';   //被重新处理过了
}
$sql .= "select()";
echo $sql;die();
  }
  //下面拼接输出语句
  $parsestr = '<?php $_result='.$sql.'; if ($_result): $'.$key.'=0;';
  $parsestr .= 'foreach($_result as $key=>$'.$result.'):';
  $parsestr .= '++$'.$key.';$mod = ($'.$key.' % '.$mod.' );?>';
  $parsestr .= $content;//解析在article标签中的内容
  $parsestr .= '<?php endforeach; endif;?>';
  return $parsestr;
}
}

[/code]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值