zoukankan      html  css  js  c++  java
  • taglib

    thinkphp中 taglib标签应用

     原文出处:http://blog.csdn.net/a11085013/article/details/38172653

    1、配置文件中加上:

    'APP_AUTOLOAD_PATH'         =>  '@.TagLib',


    2、在项目的/Lib/下新建 TagLib文件夹 复制TagLibHtml.class.php到该目录下面

    也可以自己定义格式Tag大驼峰命名.class.php

    实例:TagLibCms.class.php代码下面;

    3、模版

    <tagLib name="html" />

    <html:imageBtn name="add" value="新增" />

    <cms:article name="content" limit="10" cid="1">
    <h1><a href="/{$article.ename}/{$article.id}.html">hhh</a></h1>


    </cms:article>



    TagLibCms.class.php的代码:

    [code]

    <?php
    import("TagLib");
     
    class TagLibCms extends TagLib{
    private   $CategoryArr = array();
    private   $SubString = '';
    protected $tags = array(
    'article'=>array('attr'=>'name,field,limit,order,cid,where,sql,key,mod','level'=>3),
    );
      
    public function _article($attr,$content){
    $tag = $this->parseXmlAttr($attr,'article');
    $result = !empty($tag['result'])?$tag['result']:'article'; //定义数据查询的结果存放变量
    $key = !empty($tag['key'])?$tag['key']:'i';
    $mod = isset($tag['mod'])?$tag['mod']:'2';
    //print_r($tag['name']);die();
    if ($tag['name']){
    $sql = "M('{$tag['name']}')->";
    $sql .= ($tag['field'])?"field({$tag['field']})->":'';
    $sql .= ($tag['order'])?"order({$tag['order']})->":'';
    if($tag['cid']){
    $cidarr = explode(',',$tag['cid']);
    foreach($cidarr AS $k=>$v){
    $this->getSubCategory($v);
    }
    $cidstr = implode(",",$this->SubString);
    $tag['where'] = "cid IN(".$cidstr.")";
    $sql .= ($tag['where'])?"where("{$tag['where']}")->":'';
    }else{
    $sql .= ($tag['where'])?"where("{$tag['where']}")->":'';   //被重新处理过了
    }
    $sql .= "select()";
    echo $sql;die();
      }
      //下面拼接输出语句
      $parsestr = '<?php $_result='.$sql.'; if ($_result): $'.$key.'=0;';
      $parsestr .= 'foreach($_result as $key=>$'.$result.'):';
      $parsestr .= '++$'.$key.';$mod = ($'.$key.' % '.$mod.' );?>';
      $parsestr .= $content;//解析在article标签中的内容
      $parsestr .= '<?php endforeach; endif;?>';
      return $parsestr;
    }
    }

    [/code]

  • 相关阅读:
    开发Django项目01
    本地安装python2.x和python3.x双版本之后怎么使用pip
    python3.x并发编程
    centos6.8安装JDK1.8教程
    yum安装MySQL指定版本
    python爬虫爬取get请求的页面数据代码样例
    python网络爬虫学习笔记
    python通过get方式,post方式发送http请求和接收http响应-urllib urllib2
    CentOS7.5安装python-pip报Error: Nothing to do解决方法
    文件操作
  • 原文地址:https://www.cnblogs.com/wanlibingfeng/p/5857364.html
Copyright © 2011-2022 走看看