thinkphp custom tab, view direct label connection Data _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.