第一種:當咱們傳過來的搜索條件是一個數組的時候,以下圖php
像這樣的狀況,能夠這樣處理,css
由於sql語句支持in類型,也就是說支持下面這種搜索,sql
$cateStr = '(1,2,3)'; $ArticleInfo = Article::model() -> findAll("article_category_id in {$cateStr});
$cateStr = '(' . implode(',', array_values($search['article_category_id'])) . ')';
if( $search['wasteStage'] ) { $str = '(' . implode(',', array_values($search['wasteStage'])) . ')'; $wasteRecordModel = WasteRecord::model() -> findAll("waste_stage in {$str}"); $wasteRecordStageList = array(); foreach ( (array) $wasteRecordModel as $key => $val ) { $wasteRecordStageList[$key] = $val -> yuyue_id; } $criteria -> addInCondition('yuyueVisit.yuyue_id', $wasteRecordStageList); }
但是由於產品的變態需求,頁面要的是這樣的,數組
前面這個所有,咱們該怎麼處理,用全等「===」來斷定null,也能夠,可是更變態的來了,頁面中須要控制css樣式,這樣就很難維持選中的css樣式,this
個人方法是這樣的,以下圖:spa
$wasteReasonKeys = array_keys($this -> _wasteReason); foreach( $wasteReasonKeys as $key => $val) { <span style="white-space:pre"> </span>$wasteReasonNewKeys[$key] = $val +1; } $wasteReasonNewValues = array_values($this -> _wasteReason); $wasteReasonList = array_combine($wasteReasonNewKeys, $wasteReasonNewValues);
key值就是從1開始了,這樣,判斷條件是所有的時候,就依然能夠用0來判斷了。code
固然了,做爲搜索條件,確定要符合系統中的key值才能夠,因此在搜索的時候須要進一步處理,以下,
產品
if( $search['wasteReason'] ) { <span style="white-space:pre"> </span>$wasteReasonId = intval($search['wasteReason']) - 1; //這裏獲得的值必需要減去1,由於在上面作了加1的處理。 if( $wasteReasonId >= 0 ) { $yuyueId = WasteRecord::model() -> findAll("waste_status = '{$wasteReasonId}'"); <span style="white-space:pre"> </span>$yuyueIdArr = array(); foreach ( (array) $yuyueId as $key => $val ) { $yuyueIdArr[$key] = $val -> yuyue_id; } $criteria -> addInCondition('yuyue.yuyue_id', $yuyueIdArr); } }