当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::oneOf方法代码示例

本文整理汇总了PHP中Core\Helper\Utility\Validator::oneOf方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::oneOf方法的具体用法?PHP Validator::oneOf怎么用?PHP Validator::oneOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Core\Helper\Utility\Validator的用法示例。


在下文中一共展示了Validator::oneOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['g.category_id'] = $validator->required('商品分类不能为空')->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id');
     // 这里支持多品牌查询
     $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id'));
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin);
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax);
     $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 属性过滤
     $filter = $validator->validate('filter');
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('g.sort_order', 'desc');
     $orderByParam[] = array('g.goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 45;
     // 每页固定显示 45 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Category|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $filter . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_category.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $goodsCategoryService = new GoodsCategoryService();
     $category = $goodsCategoryService->loadCategoryById($searchFormQuery['g.category_id'], 1800);
     if ($category->isEmpty()) {
         $this->addFlashMessage('分类[' . $searchFormQuery['category_id'] . ']不存在');
         goto out_fail;
     }
     $smarty->assign('category', $category);
     $metaData = json_decode($category['meta_data'], true);
     $metaFilterArray = @$metaData['filterArray'];
     // 1. 我们需要在左侧显示分类层级结构
     $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray($category['parent_meta_id'], false, 1800);
     $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray);
     /**
      * 构造 Filter 数组,结构如下
      *
      * array(
      *      '商品品牌' => array(
      *              filterKey => 'brand_id'
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              ),
      *      '颜色' => array(
      *              filterKey => 'filter',
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              )
      * )
      *
      */
     $goodsFilterArray = array();
     // filter 查询在这个条件下进行
     $goodsFilterQueryCond = array_merge($this->searchExtraCondArray, array(array('g.category_id', '=', $searchFormQuery['g.category_id'])));
     // 2. 商品品牌查询
     $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0);
     $brandIdArray = array_map(function ($elem) {
         return $elem['brand_id'];
     }, $goodsBrandIdArray);
     if (!empty($brandIdArray)) {
         $goodsBrandService = new GoodsBrandService();
         $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray)));
         $filterBrandArray = array();
         foreach ($goodsBrandArray as $brand) {
             $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']);
         }
         if (!empty($filterBrandArray)) {
             $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray);
         }
     }
     // 3. 查询属性过滤
     if (!empty($metaFilterArray)) {
         $goodsTypeService = new GoodsTypeService();
         foreach ($metaFilterArray as $filterItem) {
             $goodsTypeAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($filterItem['attrItemId']);
             if ($goodsTypeAttrItem->isEmpty()) {
                 continue;
             }
             // 取得商品属性值列表
             $goodsAttrItemValueArray = SearchHelper::search(SearchHelper::Module_GoodsAttrGoods, 'min(ga.goods_attr_id) as goods_attr_id, ga.attr_item_value', array_merge($goodsFilterQueryCond, array(array('ga.attr_item_id', '=', $filterItem['attrItemId']))), null, 0, 0, 'ga.attr_item_value');
             if (!empty($goodsAttrItemValueArray)) {
//.........这里部分代码省略.........
开发者ID:jackycgq,项目名称:bzfshop,代码行数:101,代码来源:Category.php

示例2: get

 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['category_id'] = $validator->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id');
     $searchFormQuery['suppliers_id'] = $validator->digits('供货商id非法')->min(1, true, '供货商id非法')->filter('ValidatorIntValue')->validate('suppliers_id');
     $searchFormQuery['goods_name'] = $validator->validate('goods_name');
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $searchFormQuery['shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('sort_order', 'desc');
     $orderByParam[] = array('goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 10;
     // 每页固定显示 10 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 合并查询参数
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray);
     if ($totalCount <= 0) {
         goto out_display;
         // 没有商品,直接显示
     }
     // 页号可能是用户乱输入的,我们需要检查
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
         // 返回首页
     }
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     if (empty($goodsArray)) {
         goto out_display;
     }
     // 取得 商品ID 列表
     $goodsIdArray = array();
     foreach ($goodsArray as $goodsItem) {
         $goodsIdArray[] = $goodsItem['goods_id'];
     }
     // 取得商品的图片
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray);
     $currentGoodsId = -1;
     $goodsThumbImageArray = array();
     $goodsImageArray = array();
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         if ($currentGoodsId == $goodsGalleryItem['goods_id']) {
             continue;
             //每个商品我们只需要一张图片,跳过其它的图片
         }
         $currentGoodsId = $goodsGalleryItem['goods_id'];
         // 新的商品 id
         $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']);
         $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']);
     }
     // 赋值给模板
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsArray', $goodsArray);
     $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray);
     $smarty->assign('goodsImageArray', $goodsImageArray);
     out_display:
     $smarty->display('goods_search.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
开发者ID:jackycgq,项目名称:bzfshop,代码行数:91,代码来源:Search.php

示例3: get

 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchKeywords = $validator->validate('keywords');
     $searchFormQuery['g.goods_name'] = $searchKeywords;
     // 这里支持多品牌查询
     $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id'));
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin);
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax);
     $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('g.sort_order', 'desc');
     $orderByParam[] = array('g.goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 45;
     // 每页固定显示 45 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $goodsCategoryService = new GoodsCategoryService();
     // 1. 我们需要在左侧显示分类层级结构
     $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0, false, 1800);
     $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray);
     /**
      * 构造 Filter 数组,结构如下
      *
      * array(
      *      '商品品牌' => array(
      *              filterKey => 'brand_id'
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              ),
      *      '颜色' => array(
      *              filterKey => 'filter',
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              )
      * )
      *
      */
     $goodsFilterArray = array();
     // filter 查询在这个条件下进行
     $goodsFilterQueryCond = array_merge(QueryBuilder::buildSearchParamArray(array('g.goods_name' => $searchKeywords)), $this->searchExtraCondArray);
     // 2. 商品品牌查询
     $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0);
     $brandIdArray = array_map(function ($elem) {
         return $elem['brand_id'];
     }, $goodsBrandIdArray);
     if (!empty($brandIdArray)) {
         $goodsBrandService = new GoodsBrandService();
         $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray)));
         $filterBrandArray = array();
         foreach ($goodsBrandArray as $brand) {
             $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']);
         }
         if (!empty($filterBrandArray)) {
             $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray);
         }
     }
     if (!empty($goodsFilterArray)) {
         $smarty->assign('goodsFilterArray', $goodsFilterArray);
     }
     // 3. 商品属性过滤   TODO: 等以后扩展,看看 Search 怎么做属性过滤
     // 4. 商品查询
     // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析
     // 合并查询参数
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray);
     if ($totalCount <= 0) {
         goto out_display;
         // 没有商品,直接显示
     }
     // 页号可能是用户乱输入的,我们需要检查
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
         // 返回首页
     }
     $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     if (empty($goodsArray)) {
//.........这里部分代码省略.........
开发者ID:jackycgq,项目名称:bzfshop,代码行数:101,代码来源:Search.php


注:本文中的Core\Helper\Utility\Validator::oneOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。