本文整理匯總了PHP中Core\Helper\Utility\Validator::required方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::required方法的具體用法?PHP Validator::required怎麽用?PHP Validator::required使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Core\Helper\Utility\Validator
的用法示例。
在下文中一共展示了Validator::required方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getRequestUrl
public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
{
// 參數驗證
$validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl));
$orderId = $validator->required()->digits()->min(1)->validate('orderId');
$returnUrl = $validator->required()->validate('returnUrl');
$notifyUrl = $validator->required()->validate('notifyUrl');
$this->validate($validator);
//設置訂單 ID
$this->orderId = $orderId;
// 取得訂單
$orderBasicService = new OrderBasicService();
$orderInfo = $orderBasicService->loadOrderInfoById($orderId);
if (empty($orderInfo) || $orderInfo->isEmpty()) {
throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
}
$desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'] . '|WAP';
// 構造要請求的參數數組,無需改動
$parameterCreate = array("req_data" => '<direct_trade_create_req><subject>' . $desc . '</subject><out_trade_no>' . $orderInfo['order_sn'] . '_' . $orderInfo['order_id'] . '</out_trade_no><total_fee>' . Money::toDisplay($orderInfo['order_amount'], 2) . "</total_fee><seller_account_name>" . $this->account . "</seller_account_name><notify_url>" . $notifyUrl . "</notify_url><out_user>" . $orderInfo['user_id'] . "</out_user><merchant_url></merchant_url>" . "<call_back_url>" . $returnUrl . "</call_back_url></direct_trade_create_req>", "service" => $this->configServiceCreate, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "req_id" => date("Ymdhms"), "format" => $this->configFormat, "v" => $this->configVersion);
// 首先申請 Token
$result = $this->callAlipayWapGateway($this->buildRequestLinkData($parameterCreate));
// 調用GetToken方法,並返回token
$token = $this->getToken($result);
if (!$token) {
printLog($this->getGatewayType() . ' 獲取 token 失敗');
return null;
}
// 構造要請求的參數數組,無需改動
$parameterExecute = array("req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>", "service" => $this->configServiceExecute, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "call_back_url" => $returnUrl, "format" => $this->configFormat, "v" => $this->configVersion);
return $this->configGateway . $this->buildRequestLinkData($parameterExecute);
}
示例2: post
public function post($f3)
{
// 權限檢查
$this->requirePrivilege('manage_plugin_plugin_configure');
global $smarty;
// 參數驗證
$validator = new Validator($f3->get('POST'));
$yiqifacps_rate_web = $validator->required()->validate('yiqifacps_rate_web');
$yiqifacps_rate_mobile = $validator->required()->validate('yiqifacps_rate_mobile');
$qqcaibei_key1 = $validator->required()->validate('qqcaibei_key1');
$qqcaibei_key2 = $validator->required()->validate('qqcaibei_key2');
$yiqifacps_duration = $validator->required()->digits()->min(1)->validate('yiqifacps_duration');
if (!$this->validate($validator)) {
goto out_display;
}
// 保存設置
YiqifaCpsPlugin::saveOptionValue('yiqifacps_rate_web', $yiqifacps_rate_web);
YiqifaCpsPlugin::saveOptionValue('yiqifacps_rate_mobile', $yiqifacps_rate_mobile);
YiqifaCpsPlugin::saveOptionValue('yiqifacps_duration', $yiqifacps_duration);
YiqifaCpsPlugin::saveOptionValue('qqcaibei_key1', $qqcaibei_key1);
YiqifaCpsPlugin::saveOptionValue('qqcaibei_key2', $qqcaibei_key2);
$this->addFlashMessage('保存設置成功');
out_display:
$smarty->display('yiqifacps_configure.tpl', 'post');
}
示例3: 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');
}
示例4: post
public function post($f3)
{
global $smarty;
// 首先做參數合法性驗證
$validator = new Validator($f3->get('POST'));
$input = array();
$input['user_name'] = $validator->required('用戶名不能為空')->validate('user_name');
$input['password'] = $validator->required('密碼不能為空')->validate('password');
$p_captcha = $validator->required('驗證碼不能為空')->validate('captcha');
if (!$this->validate($validator)) {
goto out_fail;
}
// 檢查驗證碼是否有效
$captchaController = new \Controller\Image\Captcha();
if (!$captchaController->validateCaptcha($p_captcha)) {
$this->addFlashMessage("驗證碼錯誤");
goto out_fail;
}
$adminService = new AdminUserService();
// 驗證用戶登陸
$admin = $adminService->doAuthAdmin($input['user_name'], $input['user_name'], $input['password']);
if (!$admin) {
$this->addFlashMessage("登陸失敗,用戶名、密碼錯誤");
goto out_fail;
}
// 記錄用戶的登陸信息
$adminUserInfo = $admin->toArray();
unset($adminUserInfo['password']);
// 不要記錄密碼
// 取得用戶的角色權限
$adminUserInfo['role_action_list'] = '';
if ($adminUserInfo['role_id'] > 0) {
$metaRoleService = new MetaRoleService();
$role = $metaRoleService->loadRoleById($adminUserInfo['role_id']);
if (!$role->isEmpty()) {
// 賦值角色權限
$adminUserInfo['role_action_list'] = $role['meta_data'];
}
}
AuthHelper::saveAuthUser($adminUserInfo);
try {
// 記錄用戶登錄日誌
AdminLog::logAdminOperate('user.login', '用戶登錄', 'IP:' . $f3->get('IP'));
} catch (\Exception $e) {
// do nothing
}
$this->addFlashMessage("登陸成功");
// 跳轉到用戶之前看的頁麵,如果之前沒有看過的頁麵那就回到首頁
RouteHelper::jumpBack($this, '/', true);
return;
// 這裏正常返回
out_fail:
// 失敗從這裏入口
$smarty->display('user_login.tpl', 'User|Login|post');
}
示例5: updateUserFirstAddress
/**
* 更新用戶的第一個地址信息
*
* @return object 返回新的地址對象
*
* @param int $userId 用戶數字 ID
* @param array $addressInfo 包含地址信息的數組
*/
public function updateUserFirstAddress($userId, array $addressInfo)
{
// 參數驗證
$validator = new Validator(array('userId' => $userId, 'addressInfo' => $addressInfo));
$userId = $validator->required()->digits()->min(1)->validate('userId');
$addressInfo = $validator->required()->requireArray(false)->validate('addressInfo');
$this->validate($validator);
$firstAddress = $this->loadUserFirstAddress($userId);
// 補充、修正數據
$addressInfo['user_id'] = $userId;
$firstAddress->copyFrom($addressInfo);
$firstAddress->save();
return $firstAddress;
}
示例6: 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');
if (!$this->validate($validator)) {
goto out_fail;
}
// 檢查驗證碼是否有效
$captchaController = new \Controller\Image\Captcha();
if (!$captchaController->validateCaptcha($p_captcha)) {
$this->addFlashMessage("驗證碼錯誤");
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');
// 設置用戶名在網頁顯示
ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
$this->addFlashMessage("注冊成功");
// 跳轉到用戶之前看的頁麵,如果之前沒有看過的頁麵那就回到首頁
RouteHelper::jumpBack($this, '/', true);
return;
// 這裏正常返回
out_fail:
// 失敗,從這裏出口
$smarty->display('user_login.tpl', 'User|Register|post');
}
示例7: getRequestUrl
public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
{
// 參數驗證
$validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl));
$orderId = $validator->required()->digits()->min(1)->validate('orderId');
$returnUrl = $validator->required()->validate('returnUrl');
$this->validate($validator);
$this->orderId = $orderId;
//設置訂單 ID
// 自己調用 notify 完成訂單支付
$this->doNotifyUrl(null);
return $returnUrl . '?order_id=' . $orderId;
//返回 returnUrl
}
示例8: post
public function post($f3)
{
global $smarty;
// 首先做參數合法性驗證
$validator = new Validator($f3->get('POST'));
$input = array();
$input['user_name'] = $validator->required('用戶名不能為空')->validate('user_name');
$input['password'] = $validator->required('密碼不能為空')->validate('password');
$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();
// 驗證用戶登陸
$user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
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_login.tpl', 'User|Login|post');
}
示例9: Edit
public function Edit($f3)
{
// 權限檢查
$this->requirePrivilege('manage_goods_brand_listbrand');
global $smarty;
// 參數驗證
$validator = new Validator($f3->get('GET'));
$brand_id = $validator->digits()->min(1)->validate('brand_id');
if (!$brand_id) {
$brand_id = 0;
}
$goodsBrandService = new GoodsBrandService();
$goodsBrand = $goodsBrandService->loadBrandById($brand_id);
if (!$f3->get('POST')) {
// 沒有 post ,隻是普通的顯示
goto out_display;
}
unset($validator);
$validator = new Validator($f3->get('POST'));
$goodsBrand->brand_name = $validator->required()->validate('brand_name');
$goodsBrand->brand_desc = $validator->required()->validate('brand_desc');
$goodsBrand->brand_logo = $validator->validate('brand_logo');
$goodsBrand->is_custom = $validator->digits()->filter('ValidatorIntValue')->validate('is_custom');
$goodsBrand->custom_page = $f3->get('POST[custom_page]');
if (!$this->validate($validator)) {
goto out_display;
}
$goodsBrand->save();
if (0 == $brand_id) {
$this->addFlashMessage('新建商品品牌成功');
} else {
$this->addFlashMessage('更新商品品牌成功');
}
// 記錄管理員日誌
AdminLog::logAdminOperate('goods.brand.edit', '編輯品牌', $goodsBrand->brand_name);
out_display:
// 新建的品牌,reRoute 到編輯頁麵
if (!$brand_id) {
RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Brand/Edit', array('brand_id' => $goodsBrand->brand_id), true));
}
//給 smarty 模板賦值
$smarty->assign($goodsBrand->toArray());
$smarty->display('goods_brand_edit.tpl');
return;
out_fail:
// 失敗從這裏退出
RouteHelper::reRoute($this, '/Goods/Brand/ListBrand');
}
示例10: post
public function post($f3)
{
global $smarty;
// 首先做參數合法性驗證
$validator = new Validator($f3->get('POST'));
$input = array();
$input['oldpassword'] = $validator->validate('oldpassword');
$input['password'] = $validator->validate('password');
$input['email'] = $validator->validate('email');
$input['mobile_phone'] = $validator->digits('手機號格式不對')->validate('mobile_phone');
// 用戶打算修改密碼
if (!Utils::isBlank($input['password'])) {
$validator->required('必須提供舊密碼才能修改密碼')->validate('oldpassword');
}
// 提供的舊密碼,但是新密碼為空
if (!Utils::isBlank($input['oldpassword'])) {
$validator->required('新密碼不能為空')->validate('password');
}
if (!$this->validate($validator)) {
goto out_fail;
}
$userInfo = AuthHelper::getAuthUser();
$userService = new UserService();
$user = $userService->loadUserById($userInfo['user_id']);
if (!$user) {
// 非法用戶,應該讓它自動登陸出去
$this->addFlashMessage('非法登陸用戶');
RouteHelper::reRoute($this, '/User/Logout', false);
}
// 用戶打算修改密碼,但是舊密碼不對
if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) {
$this->addFlashMessage('舊密碼不對');
goto out_fail;
}
// 更新數據
unset($input['oldpassword']);
$userService->updateUser($user, $input);
// 更新認證記錄
AuthHelper::removeAuthUser();
AuthHelper::saveAuthUser($user->toArray());
$this->addFlashMessage('資料更新成功');
RouteHelper::reRoute($this, '/My/Profile');
return;
// 這裏正常返回
out_fail:
// 失敗返回
$smarty->display('my_profile.tpl', 'post');
}
示例11: post
public function post($f3)
{
global $smarty;
// 首先做參數合法性驗證
$validator = new Validator($f3->get('POST'));
$input = array();
$input['phone'] = $validator->validate('phone');
$input['address'] = $validator->validate('address');
$input['oldpassword'] = $validator->validate('oldpassword');
$input['password'] = $validator->validate('password');
// 用戶打算修改密碼
if (!Utils::isBlank($input['password'])) {
$validator->required('必須提供舊密碼才能修改密碼')->validate('oldpassword');
}
// 提供的舊密碼,但是新密碼為空
if (!Utils::isBlank($input['oldpassword'])) {
$validator->required('新密碼不能為空')->validate('password');
}
if (!$this->validate($validator)) {
goto out;
}
$authSupplierUser = AuthHelper::getAuthUser();
$supplierUserService = new SupplierUserService();
// 驗證用戶登陸
$supplierUser = $supplierUserService->loadSupplierById($authSupplierUser['suppliers_id']);
if ($supplierUser->isEmpty()) {
$this->addFlashMessage("非法登陸用戶");
RouteHelper::reRoute($this, '/User/Logout', false);
}
// 用戶打算修改密碼,但是舊密碼不對
if (!empty($input['password']) && !$supplierUserService->verifyPassword($authSupplierUser['suppliers_id'], $input['oldpassword'])) {
$this->addFlashMessage('舊密碼不對');
goto out;
}
// 更新數據
unset($input['oldpassword']);
$supplierUserService->updateSupplier($supplierUser, $input);
// 記錄用戶的登陸信息
$supplierUserInfo = $supplierUser->toArray();
unset($supplierUserInfo['password']);
// 不要記錄密碼
AuthHelper::saveAuthUser($supplierUserInfo);
$this->addFlashMessage("修改資料成功");
$smarty->assign($supplierUserInfo);
out:
// 從這裏出去
$smarty->display('my_profile.tpl');
}
示例12: ListAttrItem
public function ListAttrItem($f3)
{
// 參數驗證
$validator = new Validator($f3->get('GET'));
$meta_id = $validator->required()->digits()->min(1)->validate('typeId');
$errorMessage = '';
if (!$this->validate($validator)) {
$errorMessage = implode('|', $this->flashMessageArray);
goto out_fail;
}
// 檢查緩存
$cacheKey = md5(__FILE__ . '\\' . __METHOD__ . '\\' . $meta_id);
$attrItemArray = $f3->get($cacheKey);
if (!empty($attrItemArray)) {
goto out;
}
$goodsTypeService = new GoodsTypeService();
$attrItemArray = $goodsTypeService->fetchGoodsTypeAttrItemArray($meta_id);
$f3->set($cacheKey, $attrItemArray, 300);
//緩存 5 分鍾
out:
$f3->expire(60);
// 客戶端緩存 1 分鍾
Ajax::header();
echo Ajax::buildResult(null, null, $attrItemArray);
return;
out_fail:
Ajax::header();
echo Ajax::buildResult(-1, $errorMessage, null);
}
示例13: 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;
}
示例14: GalleryThumb
/**
* 根據 goods_id 得到一個商品的圖片集
*
* @param $f3
*/
public function GalleryThumb($f3)
{
// 參數驗證
$validator = new Validator($f3->get('GET'));
$errorMessage = '';
$goods_id = $validator->required()->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
if (!$this->validate($validator)) {
$errorMessage = implode('|', $this->flashMessageArray);
goto out_fail;
}
$goodsGalleryService = new GoodsGalleryService();
$galleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id);
$thumImageList = array();
foreach ($galleryArray as $galleryItem) {
$thumImageList[] = array('img_id' => $galleryItem['img_id'], 'thumb_url' => RouteHelper::makeImageUrl($galleryItem['thumb_url']));
}
out:
Ajax::header();
echo Ajax::buildResult(null, null, $thumImageList);
return;
out_fail:
// 失敗,返回出錯信息
Ajax::header();
echo Ajax::buildResult(-1, $errorMessage, null);
}
示例15: loadGoodsAttrGroupByName
/**
* 根據組名取得商品屬性組
*
* @param string $groupName
*
* @return \Core\Modal\SqlMapper
*/
public function loadGoodsAttrGroupByName($groupName)
{
// 參數驗證
$validator = new Validator(array('groupName' => $groupName));
$groupName = $validator->required()->validate('groupName');
$this->validate($validator);
return $this->loadMetaByTypeAndName(GoodsAttrGroup::META_TYPE, $groupName);
}