## 简介 文件名:condition.class.php 名称:筛选条件生成辅助 作用:用于简化筛选,搜索条件生成时的大量代码; 作者:高飞 QQ:56667115 官网:[http://www.dtmoban.com/]() ## 为何要使用condition方法 condition不但简化了大量代码,让destoon二次开发变得更简单,同时也有严格的过虑机制。 在安全方面开发者不用再逐个页面的维护代码,只需要更新condition.class.php即可。 ## 示列 原代码: ``` $thumb = isset($thumb) ? intval($thumb) : 0; $vip = isset($vip) ? intval($vip) : 0; $typeid = isset($typeid) && isset($TYPE[$typeid]) ? intval($typeid) : 99; if(!$areaid && $cityid && strpos($DT_URL, 'areaid') === false) { $areaid = $cityid; $ARE = $AREA[$cityid]; } $fromdate = isset($fromdate) && is_date($fromdate) ? $fromdate : ''; $fromtime = $fromdate ? strtotime($fromdate.' 0:0:0') : 0; $todate = isset($todate) && is_date($todate) ? $todate : ''; $totime = $todate ? strtotime($todate.' 23:59:59') : 0; $condition = ''; if($catid) $condition .= ($CAT['child']) ? " AND catid IN (".$CAT['arrchildid'].")" : " AND catid=$catid"; if($areaid) $condition .= ($ARE['child']) ? " AND areaid IN (".$ARE['arrchildid'].")" : " AND areaid=$areaid"; if($thumb) $condition .= " AND thumb<>''"; if($vip) $condition .= " AND vip>0"; if($typeid != 99) $condition .= " AND typeid=$typeid"; if($fromtime) $condition .= " AND edittime>=$fromtime"; if($totime) $condition .= " AND edittime<=$totime"; ``` 简化后代码: ``` $condition = condition::field('catid[int],areaid[int]')->and()->field('thumb','<>','null')->and()->field('vip','>','0')->and()->minmax('edittime[time]',$fromdate,$todate)->and()->field('typeid','=',$typeid,99)->return(); ``` 以上筛选代码在destoon系统中各种常用条件都涉及到了,这样是不是变得简单多了。 那么下面开始开心的跟着高飞一起来学习 condition.class.php 吧 # 打赏 您的支持是我最大的动力哦,立即通过微信扫一扫犒劳下高飞吧! ![](images/weixin.jpg)