另外模仿写了input标签和compare标签,都可以使用,因为不涉及数据库,就db那个标签在html上要怎么显示,我要输入查询的结果  
求大神赐教

解决方案 »

  1.   

    <?php
    class TagLibTest extends TagLib{
    protected $tags=array(
    'input'=>array('attr'=>'type,name,id,value','close'=>0),
    'compare'=>array('attr'=>'name,value,type','alias'=>'gt,lt','close'=>1), 
    'db'=>array('attr'=>'table,order,limit,id,result','close'=>1,'level'=>3),
    );
    public function _input($attr,$content)   {
             $tag = $this->parseXmlAttr($attr,'input');
             //$name = $tag['name'];
           //$id = $tag['id'];
             //$type = $tag['type'];
             $value = $this->autoBuildVar($tag['value']);
    $str = '<input type="'.$type.'" id="'.$id.'"name="'.$name.'" value="'.$value.'" />';
             return $str;
         }
    public function _compare($attr,$content,$type){
    //exit('123');
    $tag = $this->parseXmlAttr($attr,'compare');
    $type=$tag['type']?$tag['type']:$type;
    $type=($type=="gt"?">":"<");
    $str=$tag['name'].$type.$tag['value'];
    //var_dump($str);exit;
    return $str;
    }
    public function _gt($attr,$content){
    //exit('123');
    return $this->_compare($attr,$content,"gt");
    }
    public function _lt($attr,$content){
    return $this->_compare($attr,$content,"lt");
    }
    public function _db($attr,$content){
    $tag = $this->parseXmlAttr($attr,'db');
    $table=$tag['table']?$tag['table']:$table;
    $table=ucfirst($table);
    $order=$tag['order'];
    $limit=$tag['limit'];
    $id=$tag['id'];
    $model=M($table);
    $result=$model->order($order)->limit($limit)->select();
    //echo $model->getLastSql();exit;
    //dump($result);exit;
    //foreach($result as $id){
    //$content;
    //}
    return $result;
    }
    }
    ?>
      

  2.   

    <taglib name='Test' /><h3>测试compare</h3>
    <test:gt name="5" value="3">
    </test:gt>
    <test:lt name="3" value="5">
    </test:lt>
    <test:compare name="5" value="3" type="gt">
    </test:compare><h4>测试db</h4>
    <test:db table="Exhibit2" id="vo" order="id" limit="3" >
    111
    </test:db>已经引用了标签  但是 在html测试db中怎么获取TagLibTest中'db'标签_db函数返回的$result的结果?