dede 列表 篩選 聯動搜尋

來源:互聯網
上載者:User

大家都知道,好像聯動搜尋只能是獨立模型裡面的。搞了一會兒我就打算直接用搜尋功能的,但是想了一會兒,還是要相信自己能弄出來的。

閑話不多說,Let’s go!!這裡我們選擇nativeplace舉例,而且這裡的nativeplace我只保留的省份(嘿嘿,工作需要)。

當然是開啟list.php了(如果你不知道這個,好吧,我告訴你,聯動搜尋是用這個檔案的,位置是plus/list.php),大家可以看到有一個if判斷結構

if ($tinfos['issystem']==-1) {//others;include(DEDEINC."/arc.sglistview.class.php");$lv = new SgListView($tid,$cArr);} else {include(DEDEINC."/arc.listview.class.php");$lv = new ListView($tid);//others}

這裡的issystem就是判斷你的模型是不是獨立模型,如果值為-1就是獨立模型了,因為我們是自動模型,所有就在else包含的語句中搞搞了。

可以看到SgListView類中多了一個$cArr參數,這裡就是傳遞的nativeplace等參數,所以我也給我們的listview加上參數

然後else包含的語句變為

include(DEDEINC."/arc.listview.class.php");$nativeplace = ( (empty($nativeplace) || !is_numeric($nativeplace)) ? 0 : $nativeplace );$cArr['nativeplace'] = $nativeplace;$lv = new ListView($tid,1,$cArr);

當然了,我們傳了一個$cArr給建構函式,當然建構函式要想辦法接收了。所以我們開啟位於include/arc.listview.class.php的檔案,然後修改此類的建構函式為(原來的建構函式什麼樣子自己看):

function __construct($typeid,$uppage=1,$searchArr=array()) {//在$this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";下面加入下面一行$this->searchArr = $searchArr;}

然後這裡出現了一個$this->searchArr,所以,我們要給類加一個屬性:var $searchArr;(別跟我說你不知道加哪)。

現在我們已經傳過來nativeplace了,即$this->searchArr['nativeplace'],然後我們給查詢語句加一個判斷就大功搞成了。

在大概650行左右有if(ereg('hot|click|lastpost',$orderby))這麼一句話,在上面加上:

if(!empty($this->searchArr['nativeplace'])){$temp = $this->searchArr['nativeplace'];$dobila = "$addtable.nativeplace = $temp and";}else {$dobila = "";}

通過這幾句,我們增加了一個判斷條件$dobila,具體我就不說明了。

講$dobila加入到查詢字串就OK了,位置在,餓,不好說,這樣吧,在if(ereg('hot|click|lastpost',$orderby)這個條件判斷語句中,我把整段代碼複製過來,大家看看在哪就ok了。

if(ereg('hot|click|lastpost',$orderby)) { //如果不用預設的sortrank或id排序,使用聯集查詢(資料量大時非常緩慢)$query = "Select arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath$addFieldfrom `#@__archives` arcleft join `#@__arctype` tp on arc.typeid=tp.id$addJoinwhere $dobila {$this->addSql} $ordersql limit $limitstart,$row";} else { //普通情況先從arctiny表查出ID,然後按ID查詢(速度非常快)$t1 = ExecTime();$ids = array();$query = "Select id From `#@__arctiny` arc where {$this->addSql} $ordersql limit $limitstart,$row ";$this->dsql->SetQuery($query);$this->dsql->Execute();while($arr=$this->dsql->GetArray()){$ids[] = $arr['id'];}$idstr = join(',',$ids);if($idstr==''){return '';}else{$query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath$addFieldfrom `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id$addJoinwhere $dobila arc.id in($idstr) $ordersql ";}$t2 = ExecTime();//echo $t2-$t1;}
轉自:http://dobila.info/note/dedecms-search.html
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.