欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

TP3.2.3 亲测自定义标签通用代码

程序员文章站 2024-01-17 11:28:28
...
3.2.3自定义标签通用代码(新手第一次发)
标签库代码: namespace Think\Template\TagLib;
use Think\Template\TagLib;

class lx extends TagLib {
protected $tags = array(
'list' => array('attr' => 'type,order,limit,where','close' => 1),
);
public function _list($attr,$content) {
$type = $attr['type']; //要查询的数据表
$order = $attr['order']; //排序
$limit = $attr['limit']; //多少条数据
$where = $attr['where']; //查询条件
$str = ' $str .= '$result = M("' . $type . '")->where("' . $where . '")->order("' . $order . '")->limit(' . $limit . ')->select();';
$str .= 'foreach ($result as $v):';
$str .= '?>';
$str .= $content;
$str .= '';
return $str;
}
}
调用代码:
{$v[id]} -- {$v[user]}

注意:where 的条件字符串要有单引号,另外{$v[id]}要这样写,如果写成{$v:id}无效.该文件与Cx标签库放在同一个文件夹下...修改THINKPHP文件夹下通用配置文件. 新手第一次发,研究了三天,如果有任何BUG,请及时告知..谢谢.

AD:真正免费,域名+虚机+企业邮箱=0元