zdcms搜索参数多条件筛选的写法
类似以上图片这种条件搜索,一个字段可以使用多个条件选中查询,此查询需要以下字段支持:
联动菜单:Linkage 联动菜单多选:Linkages 复选框:Checkbox 单选按钮:Radio 下拉选择:Select
搜索条件写法:
<div class="form-group row"> <label class="col-md-2 control-label">单选字段-多条件</label> <div class="col-md-10"> <label><a class="label {if !$params.danxuananniu}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', NULL)}">不限</a></label> <!--调用单选字段数据方法--> {php $field = dr_field_options($ci->module['field']['danxuananniu']['id']);} {loop $field $value $name} <label><a class="label {if dr_is_double_search($params.danxuananniu, $value)}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', dr_get_double_search($params.danxuananniu, $value))}">{$name}</a></label> {/loop} </div> </div>
判断是否选择:
{if dr_is_double_search($params.字段名称, "当前值")} 选中了 {/if}
传入值写法:
{Router::search_url($params, '字段名称', dr_get_double_search($params.字段名称, "当前值"))}
搜索值写法原理:
关键字A|关键字B
多个条件已 | 符号分开
具体可参考zdcms自带的demo模块搜索中已经提供的示例,如下:
<div class="form-group row"> <label class="col-md-2 control-label">栏目分类</label> <div class="col-md-9"> <label><a class="label {if !$cat || $cat.child}label-success{else}label-default{/if}" href="{Router::search_url($params, 'catid', NULL)}">不限</a></label> <!--调用栏目分类,这种用法只能用于模块列表与搜索页面--> {loop $related $t} <label><a class="label {if $t.id==$cat.id}label-success{else}label-default{/if}" href="{Router::search_url($params, 'catid', $t.id)}">{$t.name}</a></label> {/loop} </div> </div> <!--category_search_field是调用当前栏目下的附加字段是否具有搜索字段功能,这种用法只能用于模块列表与搜索页面--> {category_search_field module=MOD_DIR catid=$catid} <div class="form-group row"> <label class="col-md-2 control-label">{$t.name}</label> <div class="col-md-9"> <label><a class="label {if !$params[$t.field]}label-success{else}label-default{/if}" href="{Router::search_url($params, $t.field, NULL)}">不限</a></label> {loop $t.data $v} <label><a class="label {if $v.value==$params[$t.field]}label-success{else}label-default{/if}" href="{Router::search_url($params, $t.field, $v.value)}">{$v.name}</a></label> {/loop} </div> </div> {/category_search_field} <!--按联动菜单搜索--> <div class="form-group row"> <label class="col-md-2 control-label">联动菜单</label> <div class="col-md-9"> <label><a class="label {if !$params.csxz || dr_linkage('address', $params.csxz, 0, 'child')}label-success{else}label-default{/if}" href="{Router::search_url($params, 'csxz', NULL)}">不限</a></label> <!--调用联动菜单address,pid为动态获取的地区id--> {list action=linkage code=address pid=$params.csxz} <label><a class="label {if $t.id==$params.csxz}label-success{else}label-default{/if}" href="{Router::search_url($params, 'csxz', $t.id)}">{$t.name}</a></label> {/list} </div> </div> <!--单选按钮字段搜索--> <div class="form-group row"> <label class="col-md-2 control-label">单选字段</label> <div class="col-md-9"> <label><a class="label {if !$params.danxuananniu}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', NULL)}">不限</a></label> <!--调用单选字段数据方法--> {php $field = dr_field_options($ci->module['field']['danxuananniu']['id']);} {loop $field $value $name} <label><a class="label {if $value==$params.danxuananniu}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', $value)}">{$name}</a></label> {/loop} </div> </div> <!--单选按钮字段搜索-多条件--> <div class="form-group row"> <label class="col-md-2 control-label">单选字段-多条件</label> <div class="col-md-9"> <label><a class="label {if !$params.danxuananniu}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', NULL)}">不限</a></label> <!--调用单选字段数据方法--> {php $field = dr_field_options($ci->module['field']['danxuananniu']['id']);} {loop $field $value $name} <label><a class="label {if dr_is_double_search($params.danxuananniu, $value)}label-success{else}label-default{/if}" href="{Router::search_url($params, 'danxuananniu', dr_get_double_search($params.danxuananniu, $value))}">{$name}</a></label> {/loop} </div> </div> <div class="form-group row"> <label class="col-md-2 control-label">复选字段-多条件</label> <div class="col-md-9"> <label><a class="label {if !$params.fuxuankuang}label-success{else}label-default{/if}" href="{Router::search_url($params, 'fuxuankuang', NULL)}">不限</a></label> <!--调用单选字段数据方法--> {php $field = dr_field_options($ci->module['field']['fuxuankuang']['id']);} {loop $field $value $name} <label><a class="label {if dr_is_double_search($params.fuxuankuang, $value)}label-success{else}label-default{/if}" href="{Router::search_url($params, 'fuxuankuang', dr_get_double_search($params.fuxuankuang, $value))}">{$name}</a></label> {/loop} </div> </div> <!--复选字段搜索--> <div class="form-group row"> <label class="col-md-2 control-label">复选字段</label> <div class="col-md-9"> <label><a class="label {if !$params.fuxuankuang}label-success{else}label-default{/if}" href="{Router::search_url($params, 'fuxuankuang', NULL)}">不限</a></label> <!--调用字段数据方法--> {php $field = dr_field_options($ci->module['field']['fuxuankuang']['id']);} {loop $field $value $name} <label><a class="label {if $value==$params.fuxuankuang}label-success{else}label-default{/if}" href="{Router::search_url($params, 'fuxuankuang', $value)}">{$name}</a></label> {/loop} </div> </div> <!--下拉框字段搜索--> <div class="form-group row"> <label class="col-md-2 control-label">下拉选择字段</label> <div class="col-md-9"> <label><a class="label {if !$params.xialaxuanze}label-success{else}label-default{/if}" href="{Router::search_url($params, 'xialaxuanze', NULL)}">不限</a></label> <!--调用单选字段数据方法--> {php $field = dr_field_options($ci->module['field']['xialaxuanze']['id']);} {loop $field $value $name} <label><a class="label {if $value==$params.xialaxuanze}label-success{else}label-default{/if}" href="{Router::search_url($params, 'xialaxuanze', $value)}">{$name}</a></label> {/loop} </div> </div> <div class="form-group row"> <label class="col-md-2 control-label">单一购买价格</label> <div class="col-md-9"> <!--自定义一个价格返回数组,这个都懂得,php最基础的数组用法--> {php $price=array('0,500'=>'500以内','500,1000'=>'500到1000','1000,2000'=>'1000到2000','2000,3000'=>'2000到3000','3000,0'=>'3000以上');} <label><a class="label {if !$params.dydgm}label-success{else}label-default{/if}" href="{Router::search_url($params, 'dydgm', NULL)}">不限</a></label> {loop $price $i $t} <label><a class="label {if $i==$params.dydgm}label-success{else}label-default{/if}" href="{Router::search_url($params, 'dydgm', $i)}">{$t}</a></label> {/loop} </div> </div> <div class="form-group row"> <label class="col-md-2 control-label">组合购买价格自定义</label> <div class="col-md-9"> {php $zhxgm = explode(',', $params.zhxgm);} <label><input type="text" class="form-control" value="{$zhxgm[0]}" id="zhxgm_min"></label> <label>到</label> <label><input type="text" class="form-control" value="{$zhxgm[1]}" id="zhxgm_max"></label> <label>这是自定义价格范围搜索的写法</label> </div> </div> <!--按关键字搜索--> <div class="form-group row"> <label class="col-md-2 control-label" style="padding-top:5px">内容搜索</label> <div class="col-md-6"> <div class="input-group"> <input type="text" class="form-control" onkeypress="if(event.keyCode==13) {dr_module_search();return false;}" name='keyword' value='{$keyword}' id='search_keyword'> <span class="input-group-btn"> <button class="btn blue" onclick="dr_module_search()" type="button"> <i class="fa fa-search"></i> 搜索</button> </span> </div> </div>