首页 > 技术交流 > DEDECMS5.7实现sql标签分页二次开发listsql
DEDECMS5.7实现sql标签分页二次开发listsql 2012-10-16

最新在用dedecms5.7制作一个BTOC类型的门户,在企业会员模块中要列出所以有企业会员信息,可dedecms只提供了memberlist 标签的使用,可这个标签又无法分页,于是我就想用sql标签来试试,可sql也是无法分页这个问题大了。

所以百度了几天找到个解决方案就是二次开发自己修改list标签的功能,网络上高手还是有的,只要能用先拿来再说了。一开始我怎么试都试不出来,后来我发现是自己的后台栏目设置成了封面,要改成列表选项才能行用listql这个标签,跟list一样。

下面就分享一下修改的方法:

打开include/arc.listview.class.php

找到:

  if(!is_object($ctag))    {     $ctag = $this->dtp->GetTag("list");    }
这一段,在其后添加如下代码:

      if(!is_object($ctag))    {     $ctag = $this->dtp->GetTag("listsql");     if (is_object($ctag))     {      $cquery = $ctag->GetAtt("sql");      $cquery = preg_replace("/SELECT(.*?)FROM/is", " SELECT count(*) as dd FROM ", $cquery);      $cquery = preg_replace("/ORDER(.*?)SC/is", "", $cquery);      $row = $this->dsql->GetOne($cquery);      if(is_array($row))      {       $this->TotalResult = $row['dd'];      }      else      {       $this->TotalResult = 0;      }     }    }    //end

然后找到:

   if($ctag->GetName()=="list")     {      $limitstart = ($this->PageNo-1) * $this->PageSize;      $row = $this->PageSize;      if(trim($ctag->GetInnerText())=="")      {       $InnerText = GetSysTemplets("list_fulllist.htm");      }      else      {       $InnerText = trim($ctag->GetInnerText());      }      $this->dtp->Assign($tagid,      $this->GetArcList(      $limitstart,      $row,      $ctag->GetAtt("col"),      $ctag->GetAtt("titlelen"),      $ctag->GetAtt("infolen"),      $ctag->GetAtt("imgwidth"),      $ctag->GetAtt("imgheight"),      $ctag->GetAtt("listtype"),      $ctag->GetAtt("orderby"),      $InnerText,      $ctag->GetAtt("tablewidth"),      $ismake,      $ctag->GetAtt("orderway")      )      );     }
这一段,在其后添加如下代码:

        else if($ctag->GetName()=="listsql")     {      $limitstart = ($this->PageNo-1) * $this->PageSize;      $row = $this->PageSize;      if(trim($ctag->GetInnerText())=="")      {       $InnerText = GetSysTemplets("list_fulllist.htm");      }      else      {       $InnerText = trim($ctag->GetInnerText());      }      $this->dtp->Assign($tagid,      $this->GetSqlList(      $limitstart,      $row,      $ctag->GetAtt("sql"),      $InnerText      )      );     }     //end
最后找到function GetArcList这个方法,在其后添加一个函数,代码如下:

    /**    * 通过listsql标签中sql属性传入的参数来获得一个单列的文档列表    * */   function GetSqlList($limitstart = 0, $row = 10, $sql = '', $innertext){       global $cfg_list_son;    $innertext = trim($innertext);       if ($innertext == '') {     $innertext = GetSysTemplets('list_fulllist.htm');    }    //处理SQL语句    $limitStr = " LIMIT {$limitstart},{$row}";       $this->dsql->SetQuery($sql . $limitStr);    $this->dsql->Execute('al');    $t2 = ExecTime();       //echo $t2-$t1;    $sqllist = '';    $this->dtp2->LoadSource($innertext);    $GLOBALS['autoindex'] = 0;       //获取字段    while($row = $this->dsql->GetArray("al")) {        $GLOBALS['autoindex']++;        if(is_array($this->dtp2->CTags))     {      foreach($this->dtp2->CTags as $k=>$ctag)      {       if($ctag->GetName()=='array')       {        //传递整个数组,在runphp模式中有特殊作用        $this->dtp2->Assign($k,$row);       }       else       {        if(isset($row[$ctag->GetName()]))        {         $this->dtp2->Assign($k,$row[$ctag->GetName()]);        }        else        {         $this->dtp2->Assign($k,'');        }       }      }     }        $sqllist .= $this->dtp2->GetResult();       }//while       $t3 = ExecTime();    //echo ($t3-$t2);    $this->dsql->FreeResult('al');       return $sqllist;   }   //end

上面看上去比较乱,在提供给大家已修改的源文件:点击打开链接

前台模板使用方法:

{dede:listsql  sql="select arc.mid,arc.userid,tp.company,tp.introduce,tp.product from sjjc_member as arc LEFT JOIN sjjc_member_company as tp ON arc.mid=tp.mid where mtype='企业' order by mid desc " pagesize='10' }
                   <ul>
                            <li class="l1">
                                <h3>
                                    <a target="_blank" href="/member/index.php?uid=[field:userid/]">
                                        [field:company/]
                                    </a>
                                </h3>
                                <p>
                                    [field:introduce/]...</p>
                                <span>主营产品:[field:product/]</span>
                                <bdo><a href="/member/index.php?uid=[field:userid/]" target="_blank">查看该公司所有信息</a></bdo>
                            </li>
                            <li class="l2"></li>
                            <li class="l3"><a href="/member/index.php?uid=[field:userid/]&action=guestbook"   class="a1"></a><a href="/member/index.php?uid=[field:userid/]&action=contact"     class="a2"></a></li>
                        </ul>
                    {/dede:listsql}
                       

此功能还有一个不足之处就是sql语句不知道如果用变量参数的方法来进行传递,望有高手能解答。

上一篇:dedecms中new dedesql(false)无内容问题 下一篇:织梦dedecms模板中调用会员信息标签的方法