图01
话不多说,下面开始详细教程:
首先用下面代码替换掉PHPCMS/libs/functions/extention.func.PHP文件里面的代码:
$v){ if($v['parentID']==$fIEld_value){ $array[$k]['name'] = $v['name']; $array[$k]['value'] = $k; $array[$k]['url'] = str_replace('{$'.$fIEldname.'}',$k,$urlrule); $array[$k]['menu'] = $fIEld_value == $k ? ''.$v['name'].'' : ''.$v['name'].'' ; } } return $array; }function structure_filters_url($fIEldname,$array=array(),$type = 1,$modelID) { if(empty($array)) { $array = $_GET; } else { $array = array_merge($_GET,$array); } //Todo $fIElds = getcache('model_fIEld_'.$modelID,'model'); if(is_array($fIElds) && !empty($fIElds)) { ksort($fIElds); foreach ($fIElds as $_v=>$_k) { if($_k['filtertype'] || $_k['rangetype']) { if(strpos(URLRulE,'.HTML') === FALSE) $urlpars .= '&'.$_v.'={$'.$_v.'}'; else $urlpars .= '-{$'.$_v.'}'; } } } //后期增加伪静态等其他url规则管理,apache伪静态支持9个参数 if(strpos(URLRulE,'.HTML') === FALSE) $urlrule =APP_PATH.'index.PHP?m=content&c=index&a=Lists&catID={$catID}'.$urlpars.'&page={$page}' ; else $urlrule =APP_PATH.'List-{$catID}'.$urlpars.'-{$page}.HTML'; //根据get传值构造URL if (is_array($array)) foreach ($array as $_k=>$_v) { if($_k=='page') $_v=1; if($type == 1) if($_k==$fIEldname) continue; $_findme[] = '/{\$'.$_k.'}/'; $_replaceme[] = $_v; } //type 模式的时候,构造排除该字段名称的正则 if($type==1) $filter = '(?!'.$fIEldname.'.)'; $_findme[] = '/{\$'.$filter.'([a-z0-9_]+)}/'; $_replaceme[] = ''; $urlrule = preg_replace($_findme,$_replaceme,$urlrule); return $urlrule; }/** * 生成分类信息中的筛选菜单 * @param $fIEld 字段名称 * @param $modelID 模型ID */function filters($fIEld,$modelID,$diyarr = array()) { $fIElds = getcache('model_fIEld_'.$modelID,'model'); $options = empty($diyarr) ? explode("\n",$fIElds[$fIEld]['options']) : $diyarr; $fIEld_value = intval($_GET[$fIEld]); foreach($options as $_k) { $v = explode("|",$_k); $k = trim($v[1]); $option[$k]['name'] = $v[0]; $option[$k]['value'] = $k; $option[$k]['url'] = structure_filters_url($fIEld,array($fIEld=>$k),2,$modelID); $option[$k]['menu'] = $fIEld_value == $k ? ''.$v[0].'' : ''.$v[0].'' ; } $all['name'] = '全部'; $all['url'] = structure_filters_url($fIEld,array($fIEld=>''),$modelID); $all['menu'] = $fIEld_value == '' ? ''.$all['name'].'' : ''.$all['name'].''; array_unshift($option,$all); return $option;}/** * 获取联动菜单层级 * @param $keyID 联动菜单分类ID * @param $linkageID 菜单ID * @param $leveltype 获取类型 parentID 获取父级ID child 获取时候有子栏目 arrchildID 获取子栏目数组 */function get_linkage_level($keyID,$linkageID,$leveltype = 'parentID') { $child_arr = $childs = array(); $leveltypes = array('parentID','child','arrchildID','arrchildinfo'); $datas = getcache($keyID,'linkage'); $infos = $datas['data']; if (in_array($leveltype,$leveltypes)) { if($leveltype == 'arrchildinfo') { $child_arr = explode(',',$infos[$linkageID]['arrchildID']); foreach ($child_arr as $r) { $childs[] = $infos[$r]; } return $childs; } else { return $infos[$linkageID][$leveltype]; } } }// 根据linkageID递归到父级function get_parent_url($modelID,$fIEld,$linkageID=0,$array = array()){ $modelID = intval($modelID); if(!$modelID || empty($fIEld)) return false; $fIElds = getcache('model_fIEld_'.$modelID,'model'); $keyID = $fIElds[$fIEld]['linkageID']; $datas = getcache($keyID,'linkage'); $infos = $datas['data']; if(empty($linkageID)){ $linkageID = intval($_GET[$fIEld]); if(!$linkageID) return false; } $urlrule = structure_filters_url($fIEld,array(),$modelID); $urlrule = str_replace('{$'.$fIEld.'}',$infos[$linkageID]['parentID'],$urlrule); array_unshift($array,array('name'=> $infos[$linkageID]['name'],'url'=>$urlrule)); if($infos[$linkageID]['parentID']){ return get_parent_url($modelID,$array); } return $array; }/** * 构造筛选时候的SQL语句 */function structure_filters_sql($modelID) { $sql = $fIEldname = $min = $max = ''; $fIEldvalue = array(); $modelID = intval($modelID); $model = getcache('model','commons'); $fIElds = getcache('model_fIEld_'.$modelID,'model'); $fIElds_key = array_keys($fIElds); //Todo $sql = '`status` = \'99\''; foreach ($_GET as $k=>$r) { if(in_array($k,$fIElds_key) && intval($r)!=0 && ($fIElds[$k]['filtertype'] || $fIElds[$k]['rangetype'])) { if($fIElds[$k]['formtype'] == 'linkage') { $datas = getcache($fIElds[$k]['linkageID'],'linkage'); $infos = $datas['data']; if($infos[$r]['arrchildID']) { $sql .= ' AND `'.$k.'` in('.$infos[$r]['arrchildID'].')'; } } elseif($fIElds[$k]['rangetype']) { if(is_numeric($r)) { $sql .=" AND `$k` = '$r'"; } else { $fIEldvalue = explode('_',$r); $min = intval($fIEldvalue[0]); $max = $fIEldvalue[1] ? intval($fIEldvalue[1]) : 999999; $sql .=" AND `$k` >= '$min' AND `$k` < '$max'"; } } else { $sql .=" AND `$k` = '$r'"; } } } return $sql; }/** * 分页,如去掉则分页会有问题 */function makeurlrule() { if(strpos(URLRULE,'.html') === FALSE) { return url_par('page={$'.'page}'); } else { $url = preg_replace('/-[0-9]+.html$/','-{$page}.html',get_url()); return $url; }}?>如果大家不想复制代码,也可以直接下载下面的文件覆盖即可,下载地址如下:
说明一下,这里用的是模型里的下拉框,模板里面的调用代码如下:
性别: {php $xingbie_rang = array('男|1','女|2','组合|3')}{loop filters('xingbie',$xingbie_rang) $r}{$r[menu]}{/loop}{php $sql = structure_filters_sql($modelid)}{php $urlrule = makeurlrule()} {pc:content action="lists" catid="$catid" where="$sql" num="35" order="id DESC"page="$page" moreinfo="1" urlrule="$urlrule"}{loop $data $r}href="{$r[url]}" title="{$r[Title]}" target="_blank">{$r[Title]}{/loop}{/pc}上面的代码是以性别为例的,大家可以自己修改。
如果要实现伪静态,可以参考下面的伪静态规则:
总结以上是内存溢出为你收集整理的PHPCMS列表联动筛选功能开发的详细教程全部内容,希望文章能够帮你解决PHPCMS列表联动筛选功能开发的详细教程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)