Thinkphp custom tag, view direct tag connection data. First, add a file named TagLibZpass. class. phpTagLibZpass. class. php:? In the ThinkPHPLibThinkTemplateTagLib directory :? Php * Zpass custom label designbyzpass1685 first, you need
Add a file name under the ThinkPHP \ Lib \ Think \ Template \ TagLib \ directory: 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 {
// Tag definition
Protected $ tags = array (
// Tag definition: whether to close the attr attribute list (0 or 1 by default). alias tag alias level nested hierarchy
'Select' => array ('attr' => 'table, limit, order, where, field', 'level' => 3 ),
);
Public function _ select ($ attr, $ content)
{
Static $ _ iterateParseCache = array ();
// If it has been parsed, the variable value is returned directly.
$ 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 the array repeated items.
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 in the view
The call method is
[Field: title]
This is easy to understand. www.2cto.com
This is just an example. it means that THINKPHP labels can be freely expanded...
The preceding tag example is used to query the content in the classes table.
Add a file named TagLibZpass. class. php TagLibZpass. class. php. class. php:? to the ThinkPHP \ Lib \ Think \ Template \ TagLib \ directory :? Php/* Zpass custom tag design by zpass 1685...