thinkphp自定义标签,view直接标签连接数据
首先,需要在
ThinkPHP\Lib\Think\Template\TagLib\目录下增加一个文件名叫:TagLibZpass.class.php
TagLibZpass.class.php:
<?php
/* Zpass自定义标签 design by zpass 16852868@qq.com,请别加QQ好友- -! */
class TagLibZpass extends TagLib{
// 标签定义
protected $tags = array(
// 标签定义:attr 属性列表close 是否闭合(0 或者1 默认1)alias 标签别名level 嵌套层次
'select'=>array('attr'=>'table,limit,order,where,field','level'=>3),
);
public function _select($attr,$content)
{
static $_iterateParseCache = array();
//如果已经解析过,则直接返回变量值
$cacheIterateId = md5($attr.$content);
if(isset($_iterateParseCache[$cacheIterateId]))
return $_iterateParseCache[$cacheIterateId];
$tag = $this->parseXmlAttr($attr,'table');
$db=M($tag['table']);
$list=$db->where($tag['where'])->order($tag['order'])->limit($tag['limit'])->field($tag['field'])->select();
preg_match_all("/\[field\:\w*\]/",$content,$match);
$match=$match[0];
$match=array_unique($match);//去掉数组重复项
foreach($match as $i=>$vo){
$field[$i]=substr($vo,7,count($vo)-2);
}
foreach($list as $i=>$value){
if($i==0){
$parseStr=$content;
}else{
$parseStr=$parseStr.$content;
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>