當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validator::digits方法代碼示例

本文整理匯總了PHP中Core\Helper\Utility\Validator::digits方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::digits方法的具體用法?PHP Validator::digits怎麽用?PHP Validator::digits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Core\Helper\Utility\Validator的用法示例。


在下文中一共展示了Validator::digits方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: Search

 /**
  *
  * 根據某些查詢條件取得商品的列表
  *
  * @param $f3
  */
 public function Search($f3)
 {
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $searchFormQuery = array();
     $searchFormQuery['is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale');
     $searchFormQuery['goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     $searchFormQuery['suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id');
     $searchFormQuery['goods_name'] = $validator->validate('goods_name');
     $searchFormQuery['cat_id'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('cat_id');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     // 建立查詢條件
     $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery);
     // 商品列表
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, array(array('goods_id', 'desc')), 0, 25);
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, $goodsArray);
     return;
     out_fail:
     // 失敗,返回出錯信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:34,代碼來源:Goods.php

示例2: get

 public function get($f3)
 {
     global $smarty;
     $myOrderTitleDesc = array(0 => '未付款訂單', 1 => '已付款訂單');
     // 構造查詢條件
     $searchFormQuery = array();
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $orderStatus = $f3->get('GET[orderStatus]');
     if (isset($orderStatus)) {
         $orderStatus = $searchFormQuery['order_status'] = $validator->digits('訂單狀態非法')->min(0)->filter('ValidatorIntValue')->validate('orderStatus');
     }
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 設置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $myOrderTitle = '全部訂單';
     if (isset($orderStatus)) {
         $myOrderTitle = $myOrderTitleDesc[$orderStatus];
     }
     $smarty->assign('myOrderTitle', $myOrderTitle);
     $userInfo = AuthHelper::getAuthUser();
     // 查詢訂單
     $searchFormQuery['user_id'] = $userInfo['user_id'];
     // 合並查詢參數
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     $totalCount = SearchHelper::count(SearchHelper::Module_OrderInfo, $searchParamArray);
     if ($totalCount <= 0) {
         // 沒訂單,可以直接退出了
         goto out_display;
     }
     // 頁數超過最大值,返回第一頁
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Order');
     }
     // 訂單排序
     $orderByParam = array();
     $orderByParam[] = array('order_id', 'desc');
     // 訂單列表
     $orderInfoArray = SearchHelper::search(SearchHelper::Module_OrderInfo, '*', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     foreach ($orderInfoArray as &$orderInfoItem) {
         $orderInfoItem['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfoItem['order_status']];
         $orderInfoItem['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfoItem['pay_status']];
     }
     unset($orderInfoItem);
     // 給模板賦值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderInfoArray', $orderInfoArray);
     out_display:
     $smarty->display('my_order.tpl', 'get');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:57,代碼來源:Order.php

示例3: get

 public function get($f3)
 {
     global $smarty;
     // 權限檢查
     $this->requirePrivilege('manage_misc_cron');
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 設置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     //查詢條件
     $searchFormQuery = array();
     $searchFormQuery['task_name'] = $validator->validate('task_name');
     $searchFormQuery['task_desc'] = $validator->validate('task_desc');
     $returnCode = $validator->digits()->filter('ValidatorIntValue')->validate('return_code');
     if (0 === $returnCode) {
         $searchFormQuery['task_run_time'] = array('>', 0);
         $searchFormQuery['return_code'] = 0;
     } elseif ($returnCode > 0) {
         $searchFormQuery['task_run_time'] = array('>', 0);
         $searchFormQuery['return_code'] = array('<>', 0);
     } else {
         // do nothing
     }
     //任務時間
     $taskTimeStartStr = $validator->validate('task_time_start');
     $taskTimeStart = Time::gmStrToTime($taskTimeStartStr) ?: null;
     $taskTimeEndStr = $validator->validate('task_time_end');
     $taskTimeEnd = Time::gmStrToTime($taskTimeEndStr) ?: null;
     $searchFormQuery['task_time'] = array($taskTimeStart, $taskTimeEnd);
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查詢條件
     $searchParamArray = QueryBuilder::buildQueryCondArray($searchFormQuery);
     $cronTaskService = new CronTaskService();
     $totalCount = $cronTaskService->countCronTaskArray($searchParamArray);
     if ($totalCount <= 0) {
         // 沒任務,可以直接退出了
         goto out_display;
     }
     // 頁數超過最大值,返回第一頁
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Misc/Cron');
     }
     $cronTaskArray = $cronTaskService->fetchCronTaskArray($searchParamArray, $pageNo * $pageSize, $pageSize);
     // 給模板賦值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('cronTaskArray', $cronTaskArray);
     out_display:
     $smarty->display('misc_cron.tpl');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:56,代碼來源:Cron.php

示例4: get

 public function get($f3)
 {
     // 權限檢查
     $this->requirePrivilege('manage_goods_edit_edit_get');
     global $smarty;
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能為空')->digits()->min(1)->validate('goods_id');
     // 商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('商品ID[' . $goods . ']非法');
         goto out_fail;
     }
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 設置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     //查詢條件
     $searchFormQuery = array();
     $searchFormQuery['task_name'] = array('=', GoodsCronTask::$task_name);
     $searchFormQuery['search_param'] = array('=', $goods_id);
     // 建立查詢條件
     $searchParamArray = QueryBuilder::buildQueryCondArray($searchFormQuery);
     $cronTaskService = new CronTaskService();
     $totalCount = $cronTaskService->countCronTaskArray($searchParamArray);
     if ($totalCount <= 0) {
         // 沒任務,可以直接退出了
         goto out_display;
     }
     $cronTaskArray = $cronTaskService->fetchCronTaskArray($searchParamArray, $pageNo * $pageSize, $pageSize);
     // 給模板賦值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('cronTaskArray', $cronTaskArray);
     out_display:
     $smarty->assign('goods', $goods->toArray());
     $smarty->display('goods_edit_cron.tpl');
     return;
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
開發者ID:swcug,項目名稱:bzfshop,代碼行數:48,代碼來源:Cron.php

示例5: get

 public function get($f3)
 {
     global $smarty;
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能為空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的緩存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|AjaxGoodsComment_' . $pageNo;
     // 開啟並設置 smarty 緩存時間
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view'));
     if ($smarty->isCached('ajax_goodscomment.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $this->preparePage($goods_id, $pageNo);
     out_display:
     $f3->expire(600);
     // 讓客戶端緩存 10 分鍾
     $smarty->display('ajax_goodscomment.tpl', $smartyCacheId);
     return;
     out_fail:
     // output nothing
     return;
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:27,代碼來源:GoodsComment.php

示例6: Edit

 /**
  * 更新或者新建一個快遞公司
  *
  * @param $f3
  */
 public function Edit($f3)
 {
     // 權限檢查
     $this->requirePrivilege('manage_misc_express_edit');
     global $smarty;
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     //  加載 快遞信息
     $expressService = new ExpressService();
     $expressInfo = $expressService->loadMetaById($meta_id);
     if (Request::isRequestGet()) {
         goto out_assign;
     }
     // 安全性檢查
     if ($meta_id > 0) {
         if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo->meta_type) {
             $this->addFlashMessage('非法ID[' . $meta_id . ']');
             goto out;
         }
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $inputArray = array();
     $inputArray['meta_type'] = ExpressService::META_TYPE;
     $inputArray['meta_name'] = $validator->required()->validate('meta_name');
     $inputArray['meta_ename'] = $validator->required()->validate('meta_ename');
     $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order');
     $inputArray['meta_status'] = $validator->digits()->validate('meta_status');
     $inputArray['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 保存
     $expressInfo->copyFrom($inputArray);
     $expressInfo->save();
     $this->addFlashMessage('快遞信息保存成功');
     // POST 成功從這裏退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Misc/Express/Edit', array('meta_id' => $expressInfo->meta_id), true));
     return;
     out_assign:
     $smarty->assign($expressInfo->toArray());
     out:
     $smarty->display('misc_express_edit.tpl');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:51,代碼來源:Express.php

示例7: get

 public function get($f3)
 {
     global $smarty;
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 設置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     // 構造查詢條件
     $searchFormQuery = array();
     $searchFormQuery['oi.user_id'] = $userInfo['user_id'];
     // 合並查詢參數
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     // 查詢訂單
     $totalCount = SearchHelper::count(SearchHelper::Module_OrderGoodsOrderInfo, $searchParamArray);
     if ($totalCount <= 0) {
         // 沒訂單,可以直接退出了
         goto out_display;
     }
     // 頁數超過最大值,返回第一頁
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Order');
     }
     // 訂單排序
     $orderByParam = array();
     $orderByParam[] = array('og.rec_id', 'desc');
     // 訂單列表
     $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.order_id, og.goods_id, og.goods_attr, og.goods_number, og.goods_price, og.shipping_fee' . ', og.create_time, og.order_goods_status, oi.order_sn, oi.pay_time', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 給模板賦值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     out_display:
     $smarty->display('my_order.tpl', 'get');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:46,代碼來源:Order.php

示例8: ListChildTreeNodeAllStr

 public function ListChildTreeNodeAllStr($f3)
 {
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $treeKey = $validator->required()->validate('treeKey');
     $parentId = $validator->digits()->min(0)->validate('parentId');
     $parentId = $parentId ?: 0;
     // 用戶也可以通過 treeNodeName 來做查詢
     $treeNodeName = $validator->validate('treeNodeName');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     // 檢查緩存
     $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $treeKey . '\\' . $parentId . '\\' . $treeNodeName);
     $outputArray = $f3->get($cacheKey);
     if (!empty($outputArray)) {
         goto out;
     }
     $metaTreeService = new MetaTreeService();
     if (!empty($treeNodeName)) {
         $treeNode = $metaTreeService->loadTreeNodeWithTreeKeyAndName($treeKey, $treeNodeName);
         if (!$treeNode->isEmpty()) {
             $parentId = $treeNode['meta_id'];
         }
     }
     // 取得樹形的層級結構
     $treeNodeArray = $metaTreeService->fetchChildTreeNodeArrayAll($treeKey, $parentId);
     // 構建顯示輸出
     $outputArray = array();
     function buildHierarchyArray(&$outputArray, $treeNodeArray, $separator = '')
     {
         $hierarchySeparator = '---------->';
         foreach ($treeNodeArray as $treeNodeItem) {
             $outputItem = array();
             $outputItem['meta_id'] = $treeNodeItem['meta_id'];
             $outputItem['meta_name'] = $treeNodeItem['meta_name'];
             $outputItem['display_text'] = $separator . $treeNodeItem['meta_name'];
             $outputArray[] = $outputItem;
             // 有子節點,遞歸建立子節點
             if (isset($treeNodeItem['child_list'])) {
                 buildHierarchyArray($outputArray, $treeNodeItem['child_list'], $separator . $hierarchySeparator);
             }
         }
     }
     buildHierarchyArray($outputArray, $treeNodeArray, '');
     $f3->set($cacheKey, $outputArray, 600);
     //緩存 10 分鍾
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, $outputArray);
     return;
     out_fail:
     // 失敗,返回出錯信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:58,代碼來源:Tree.php

示例9: get

 public function get($f3)
 {
     global $smarty;
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 設置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 用戶總共有資金餘額
     $smarty->assign('userMoney', $userInfo['user_money']);
     $accountLog = new AccountLogService();
     // 用戶總共有多少account_log
     $totalCount = $accountLog->countUserMoneyArray($userInfo['user_id'], 10);
     //緩存 10 秒鍾
     if ($totalCount <= 0) {
         // 沒資金變動記錄,可以直接退出了
         goto out_display;
     }
     $smarty->assign('totalCount', $totalCount);
     // 頁數超過最大值,返回第一頁
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Money');
     }
     // 傳遞分頁的變量
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // account_log 列表
     $accountLogArray = $accountLog->fetchUserMoneyArray($userInfo['user_id'], $pageNo * $pageSize, $pageSize, 10);
     //緩存 10 秒鍾
     foreach ($accountLogArray as &$accountLogItem) {
         $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']];
     }
     unset($accountLogItem);
     $smarty->assign('accountLogArray', $accountLogArray);
     out_display:
     $smarty->display('my_money.tpl', 'get');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:45,代碼來源:Money.php

示例10: countSupplierGoodsArray

 /**
  * 取得供貨商下麵商品的總數,用於分頁顯示
  *
  * @return int 商品總數
  *
  * @param int $suppliers_id 供貨商的ID
  * @param int $ttl          緩存時間
  */
 public function countSupplierGoodsArray($suppliers_id, $ttl = 0)
 {
     // 參數驗證
     $validator = new Validator(array('suppliers_id' => $suppliers_id, 'ttl' => $ttl));
     $suppliers_id = $validator->required()->digits()->min(1)->validate('suppliers_id');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $this->validate($validator);
     return $this->_countArray('goods', array(array('suppliers_id = ? AND is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1', $suppliers_id)), null, $ttl);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:17,代碼來源:Supplier.php

示例11: post

 public function post($f3)
 {
     // 用戶沒有登陸,讓用戶去登陸
     if (!AuthHelper::isAuthUser()) {
         // 如果已經記錄了一個回跳 URL ,則不要再覆蓋這個記錄了
         RouteHelper::reRoute($this, '/User/Login', !RouteHelper::hasRememberUrl());
     }
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('POST'));
     $addressInfo = array();
     $addressInfo['consignee'] = $validator->required('姓名不能為空')->validate('consignee');
     $addressInfo['address'] = $validator->required('地址不能為空')->validate('address');
     $addressInfo['mobile'] = $validator->required('手機號碼不能為空')->digits('手機號碼格式不正確')->validate('mobile');
     $addressInfo['tel'] = $validator->validate('tel');
     $addressInfo['zipcode'] = $validator->digits('郵編格式不正確')->validate('zipcode');
     $postScript = $validator->validate('postscript');
     // 訂單附言
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     $cartBasicService->loadFromStorage();
     // 加載購物車的數據
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('購物車為空');
         goto out_fail;
     }
     // 做一次購物車計算
     $cartBasicService->calcOrderPrice();
     // 如果購物車裏麵有錯誤消息,我們需要顯示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
     }
     // 更新用戶的地址信息
     $userInfo = AuthHelper::getAuthUser();
     $userAddressService = new UserAddressService();
     $userAddressService->updateUserFirstAddress($userInfo['user_id'], $addressInfo);
     // 地址信息放入購物車結構
     $cartContext->setAddressInfo($addressInfo);
     // 訂單附言放入購物車
     $cartContext->setValue('postscript', $postScript);
     // 創建或者更新訂單
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '買家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //訂單創建失敗,報錯
         $this->addFlashMessage('訂單創建失敗,請聯係客服');
         goto out_fail;
     }
     //訂單創建成功,清空購物車
     $cartBasicService->clearStorage();
     // 跳轉到支付頁麵
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Cart/Pay', array('order_id' => $orderInfo['order_id']), true));
     return;
     out_fail:
     RouteHelper::reRoute($this, '/Cart/Show');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:57,代碼來源:Show.php

示例12: post

 public function post($f3)
 {
     global $smarty;
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用戶名不能為空')->minLength(2, '用戶名最短為2個字符')->validate('user_name');
     $input['password'] = $validator->required('密碼不能為空')->minLength(6, '密碼最短為6個非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手機號格式不對')->validate('mobile_phone');
     $p_captcha = $validator->required('驗證碼不能為空')->validate('captcha');
     // 手機輸入,輸入法經常無故添加空格,我們需要去除所有的空額,防止出錯
     $p_captcha = Utils::filterAlnumStr($p_captcha);
     // 需要跳轉回去的地址
     $returnUrl = $validator->validate('returnUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 檢查驗證碼是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage('驗證碼錯誤[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']');
         goto out_fail;
     }
     $userService = new UserService();
     // 檢查用戶是否已經注冊
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已經存在');
         goto out_fail;
     }
     // 注冊用戶
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用戶注冊失敗,請稍後刷新頁麵重試');
         goto out_fail;
     }
     // 記錄用戶的登陸信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要記錄密碼
     AuthHelper::saveAuthUser($userInfo, 'normal');
     $this->addFlashMessage("注冊成功");
     if ($returnUrl) {
         header('Location:' . $returnUrl);
         return;
     } else {
         // 跳轉到用戶之前看的頁麵,如果之前沒有看過的頁麵那就回到首頁
         RouteHelper::jumpBack($this, '/', true);
     }
     return;
     // 這裏正常返回
     out_fail:
     // 失敗,從這裏出口
     $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time())));
     $smarty->display('user_register.tpl', 'User|Register|post');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:57,代碼來源:Register.php

示例13: Edit

 /**
  * 更新或者新建一個分類
  *
  * @param $f3
  */
 public function Edit($f3)
 {
     // 權限檢查
     $this->requirePrivilege('manage_goods_category_edit');
     // 參數驗證
     $validator = new Validator($f3->get('POST'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     $meta_name = $validator->validate('meta_name');
     $parent_meta_id = $validator->digits()->validate('parent_meta_id');
     $meta_sort_order = $validator->digits()->validate('meta_sort_order');
     $meta_status = $validator->digits()->validate('meta_status');
     // 篩選屬性
     $filterTypeIdArray = $validator->validate('filterTypeIdArray');
     $filterAttrItemIdArray = $validator->validate('filterAttrItemIdArray');
     if (!$this->validate($validator)) {
         goto out;
     }
     if ($parent_meta_id > 0 && $parent_meta_id == $meta_id) {
         $this->addFlashMessage('父分類不能指向自己');
         goto out;
     }
     // 構造篩選屬性結構
     $filterArray = array();
     $count = min(count($filterTypeIdArray), count($filterAttrItemIdArray));
     for ($index = 0; $index < $count; $index++) {
         $typeId = abs(intval($filterTypeIdArray[$index]));
         $attrItemId = abs(intval($filterAttrItemIdArray[$index]));
         if ($typeId <= 0 || $attrItemId <= 0) {
             // 非法值跳過
             continue;
         }
         $filterArray[] = array('typeId' => $typeId, 'attrItemId' => $attrItemId);
     }
     $meta_data = array('filterArray' => $filterArray);
     $goodsCategoryService = new GoodsCategoryService();
     $goodsCategoryService->saveCategoryById($meta_id, $parent_meta_id, $meta_name, null, json_encode($meta_data), $meta_sort_order, $meta_status);
     // 清除商品分類的緩存
     ClearHelper::clearGoodsCategory();
     $this->addFlashMessage('商品分類保存成功');
     out:
     RouteHelper::reRoute($this, '/Goods/Category');
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:48,代碼來源:Category.php

示例14: fetchGoodsGalleryPromote

 /**
  * 取得 goods 和 goods_promote 的 join 結果,同時取得 goods 對應的所有商品
  * 由於這個函數的代價非常大(幾千個商品,上萬個圖片),所以我們一定要做緩存
  *
  * @return array  array('goods' => $goodsArray, 'goodsIdToGalleryArray' => $goodsIdToGalleryArray)
  *
  * @param array  $queryCondArray 查詢條件
  * @param string $sort
  * @param  int   $offset
  * @param  int   $limit
  * @param int    $ttl            緩存時間
  *
  * @return array
  */
 public function fetchGoodsGalleryPromote($queryCondArray, $sort, $offset, $limit, $ttl = 0)
 {
     // 首先做參數驗證
     $validator = new Validator(array('sort' => $sort, 'offset' => $offset, 'limit' => $limit, 'ttl' => $ttl));
     $offset = $validator->digits()->min(0)->validate('offset');
     $limit = $validator->digits()->min(0)->validate('limit');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $sort = $validator->validate('sort');
     // 查詢商品信息
     $condArray = array();
     $condArray[] = array('g.goods_id = gp.goods_id');
     $formQuery = array();
     $formQuery['is_delete'] = 0;
     $formQuery['is_on_sale'] = 1;
     $formQuery['is_alone_sale'] = 1;
     if (!empty($queryCondArray)) {
         $condArray = array_merge($condArray, $queryCondArray);
     }
     $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery));
     $goodsArray = $this->_fetchArray(array('goods' => 'g', 'goods_promote' => 'gp'), 'g.system_tag_list, g.goods_name, g.goods_name_short, g.brand_id, g.goods_number, g.market_price, g.shop_price, g.cat_id' . ', g.sort_order, g.goods_brief, g.seo_keyword, g.goods_notice , g.virtual_buy_number, g.user_pay_number' . ', gp.* ', $condArray, array('order' => $sort), $offset, $limit, $ttl);
     // options
     // 如果沒有數據就退出
     if (empty($goodsArray)) {
         return array();
     }
     // 查詢商品圖片
     $goodsIdArray = array();
     foreach ($goodsArray as $goodsItem) {
         $goodsIdArray[] = $goodsItem['goods_id'];
     }
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray, $ttl);
     // 建立 goods_id --> goods_gallery 的反查表
     $goodsIdToGalleryArray = array();
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         if (!isset($goodsIdToGalleryArray[$goodsGalleryItem['goods_id']])) {
             $goodsIdToGalleryArray[$goodsGalleryItem['goods_id']] = array();
         }
         $goodsIdToGalleryArray[$goodsGalleryItem['goods_id']][] = $goodsGalleryItem;
     }
     return array('goods' => $goodsArray, 'goodsIdToGalleryArray' => $goodsIdToGalleryArray);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:56,代碼來源:Goods.php

示例15: loadUserFirstAddress

 /**
  * 根據用戶 id 取得用戶的第一個地址
  *
  * @return object 用戶信息記錄
  * @param int $userId  用戶數字 ID
  * @param int $ttl 緩存時間
  *
  * */
 public function loadUserFirstAddress($userId, $ttl = 0)
 {
     // 參數驗證
     $validator = new Validator(array('userId' => $userId, 'ttl' => $ttl));
     $userId = $validator->required()->digits()->min(1)->validate('userId');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $this->validate($validator);
     $user = new DataMapper('user_address');
     $user->loadOne(array('user_id=?', $userId), array('order' => 'address_id asc', 'offset' => 0, 'limit' => 1), $ttl);
     return $user;
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:19,代碼來源:Address.php


注:本文中的Core\Helper\Utility\Validator::digits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。