dd

thinkphp3.2自定义模板标签详解TagLib

jerry thinkphp 2015年11月19日 收藏
thinkphp3.2自定义模板标签详解TagLib
3.2引入方法基本与3.1相似下面介绍区别

一、存储位置

在3.1中 网站目录\Lib\TagLib  命名格式:"TagLib"+"Shop"+".class.php",
在3.2中 框架目录\Library\Think\Template\TagLib  命名格式 "Shop"+".class.php"

二、文件命名空间

在3.1中是不需要命名空间
在3.2的文件中开头需要加上如下代码
namespace Think\Template\TagLib;    
use Think\Template\TagLib;
三、class名

3.1的命名 class TagLibShop extends TagLib

3.2的命名 class Shop extends TagLib


四、标签属性读取

3.1的读取方式
//标签传入参数为$attr
public function _shoplist($attr,$content){
    $attr = $this->parseXmlAttr($attr);  //使用继承方法读取参数
    $id = $attr['id'];
}
3.2的读取方式
//标签传入参数为$tag
public function _shoplist($tag,$content){
    $id = $tag['id'];  //直接获取属性
}
加载扩展标签与3.1一样,这里就不再细表。
dd