本文整理汇总了PHP中Core\Helper\Utility\Validator::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::validate方法的具体用法?PHP Validator::validate怎么用?PHP Validator::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core\Helper\Utility\Validator
的用法示例。
在下文中一共展示了Validator::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($f3)
{
// 设置 order_refer 记录,记录在客户端
$orderRefer = array();
// 检查彩贝的记录
$caibeiRefer = $f3->get('SESSION[yiqifa_caibei_order_refer]');
if (!empty($caibeiRefer)) {
$orderRefer = $caibeiRefer;
unset($orderRefer['refer_host']);
// 去掉彩贝的 refer_host
}
// 清除彩贝记录
$f3->set('SESSION[yiqifa_caibei_order_refer]', null);
$orderRefer['utm_source'] = 'YIQIFACPS';
// 保存额外的 亿起发 参数
$validator = new Validator($_REQUEST);
$referParamArray = array();
$referParamArray['src'] = $validator->validate('src');
$referParamArray['cid'] = $validator->validate('cid');
$referParamArray['wi'] = $validator->validate('wi');
$referParamArray['channel'] = $validator->validate('channel');
$orderRefer['refer_param'] = json_encode($referParamArray);
//设置 cookie
ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration'));
// 页面跳转到商品
$url = $validator->validate('url');
$redirectUrl = empty($url) ? '/' : $url;
RouteHelper::reRoute($this, $redirectUrl);
return;
}
示例2: ListSettle
/**
* 列出结算列表
*
* @param $f3
*/
public function ListSettle($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;
// 表单查询
$formQuery = array();
//结算时间
$settleTimeStartStr = $validator->validate('settle_time_start');
$settleTimeStart = Time::gmStrToTime($settleTimeStartStr) ?: null;
$settleTimeEndStr = $validator->validate('settle_time_end');
$settleTimeEnd = Time::gmStrToTime($settleTimeEndStr) ?: null;
$formQuery['create_time'] = array($settleTimeStart, $settleTimeEnd);
//是否已经付款
$is_pay = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('is_pay');
switch ($is_pay) {
case 1:
$formQuery['pay_time'] = 0;
break;
case 2:
$formQuery['pay_time'] = array($is_pay, null);
break;
default:
break;
}
// 供货商只能查看自己的结算历史
$authSupplierUser = AuthHelper::getAuthUser();
$formQuery['suppliers_id'] = $authSupplierUser['suppliers_id'];
// 构建查询条件
$condArray = null;
if (!empty($formQuery)) {
$condArray = QueryBuilder::buildQueryCondArray($formQuery);
}
// 查询结算列表
$orderSettleService = new OrderSettleService();
$totalCount = $orderSettleService->countOrderSettleArray($condArray);
if ($totalCount <= 0) {
// 没商品,可以直接退出了
goto out;
}
// 页数超过最大值,返回
if ($pageNo * $pageSize >= $totalCount) {
RouteHelper::reRoute($this, '/Order/Settle/ListSettle');
}
// 结算列表
$orderSettleArray = $orderSettleService->fetchOrderSettleArray($condArray, $pageNo * $pageSize, $pageSize);
// 给模板赋值
$smarty->assign('totalCount', $totalCount);
$smarty->assign('pageNo', $pageNo);
$smarty->assign('pageSize', $pageSize);
$smarty->assign('orderSettleArray', $orderSettleArray);
out:
$smarty->display('order_settle_listsettle.tpl');
}
示例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: 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');
}
示例5: 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');
}
示例6: 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');
}
示例7: 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);
}
示例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);
}
示例9: Edit
/**
* 角色详情显示
*/
public function Edit($f3)
{
// 权限检查
$this->requirePrivilege('manage_account_role_edit_get');
global $smarty;
// 参数验证
$validator = new Validator($f3->get('GET'));
$meta_id = $validator->digits()->min(1)->validate('meta_id');
$meta_id = $meta_id > 0 ? $meta_id : 0;
if (!$this->validate($validator)) {
goto out;
}
// 查询角色信息
$metaRoleService = new MetaRoleService();
$role = $metaRoleService->loadRoleById($meta_id);
if (0 != $meta_id && $role->isEmpty()) {
// 不存在的角色
$this->addFlashMessage('角色不存在');
goto out;
}
if ($role->isEmpty()) {
// 新建角色
$this->requirePrivilege('manage_account_role_create');
}
if (!$f3->get('POST')) {
// 没有 post ,只是普通的显示
goto out_display;
}
// 权限检查
$this->requirePrivilege('manage_account_role_edit_post');
// 用户提交了更新请求,这里做角色信息更新
$validator = new Validator($f3->get('POST'));
$metaRoleService->saveRole($meta_id, $validator->validate('meta_name'), $validator->validate('meta_desc'), $role['meta_data']);
if (0 == $meta_id) {
$this->addFlashMessage('成功新建角色');
} else {
$this->addFlashMessage('角色信息更新成功');
}
out_display:
//给 smarty 模板赋值
$smarty->assign($role->toArray());
out:
$smarty->display('account_role_edit.tpl');
}
示例10: 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');
}
示例11: post
public function post($f3)
{
// 权限检查
$this->requirePrivilege('manage_plugin_theme_adv_configure');
// 参数验证
$validator = new Validator($f3->get('POST'));
// slider 广告设置
$imageArray = $validator->validate('image');
$urlArray = $validator->validate('url');
$targetArray = $validator->validate('target');
$imageSize = is_array($imageArray) ? count($imageArray) : 0;
$shop_index_adv_slider = array();
// 组织数据结构
for ($index = 0; $index < $imageSize; $index++) {
$shop_index_adv_slider[] = array('image' => $imageArray[$index], 'url' => $urlArray[$index], 'target' => $targetArray[$index]);
}
ShopThemePlugin::saveOptionValue('shop_index_adv_slider', json_encode($shop_index_adv_slider));
// 清除 /Shop/Index 页面
$shopClear = new ShopClear();
$shopClear->clearHomePage();
$this->addFlashMessage('保存设置成功');
RouteHelper::reRoute($this, '/Theme/Shop/AdvShopSlider');
}
示例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');
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');
}
示例13: 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');
}
示例14: 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');
}
示例15: 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');
}