First, you need to
Add a file under the Thinkphp\lib\think\template\taglib\ directory named: TagLibZpass.class.php
TagLibZpass.class.php:
/* ZPass custom Label design by ZPass 16852868@qq.com, please do not add QQ friends--! */
Class Taglibzpass extends taglib{
Label definition
Protected $tags = Array (
Tag definition: attr attribute list close whether closed (0 or 1 default 1) alias tag alias level nesting hierarchy
' Select ' =>array (' attr ' = ' table,limit,order,where,field ', ' Level ' =>3),
);
Public Function _select ($attr, $content)
{
Static $_iterateparsecache = Array ();
Returns the value of a variable directly if it has already been resolved
$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);//Remove array duplicates
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;
}
foreach ($match as $j = = $vo) {
$parseStr =str_replace ($vo, $value [$field [$j]], $PARSESTR);
}
}
$_iterateparsecache[$cacheIterateId] = $parseStr;
if (!emptyempty ($PARSESTR)) {
return $this->tpl->parse ($PARSESTR);
}
return;
}
}
?>
Then write on the view.
The method that is called is
[Field:title]
That's easy to understand, www.2cto.com.
I'm just an example of this, representing the freedom to expand thinkphp tags ... Make your own signature tag
The above tag example is actually querying the contents of the Classes table.
http://www.bkjia.com/PHPjc/478489.html www.bkjia.com true http://www.bkjia.com/PHPjc/478489.html techarticle first, you need to add a file under the Thinkphp\lib\think\template\taglib\ directory named: TagLibZpass.class.php TagLibZpass.class.php:? PHP/* ZPass Custom Label design by ZPass 1685 ...