ThinkPHP中的$this->success()与$this->error()方法的使用

本文介绍如何在ThinkPHP框架中配置错误和成功页面,通过简单修改配置即可实现跳转到不同模板文件,提高用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为什么$this->error()和$this->success()跳转到同一个模板文件?
 Thinkphp的默认配置错误和成功是一个模板,可以在配置里面添加
 'TMPL_ACTION_ERROR'=>'Public:error' //默认错误跳转到Public文件夹下面的error.html文件
 'TMPL_ACTION_SUCCESS'=>'Public:success' //默认成功跳转到对应的Public文件夹下面的success.html文件

转载于:https://www.cnblogs.com/luodao1991/p/3165557.html

/** * 添加商品预览 * */ public function goods() { $filter = $this->request->param('filter'); $offset = $this->request->param('offset'); $limit = $this->request->param('limit'); $startDate = $this->request->param('startDate'); $endDate = $this->request->param('endDate'); $shop_id = $this->request->param('shop_id'); if ($this->request->isAjax()) { //list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $filters = json_decode($filter,true); //halt($filters); // $correlation = "wanlshop_groups.state = 'success'"; $correlation = "1 = 1"; if(!empty($filters['shopname'])){ //$db::name('wanlshop_groups_order')->where()->column('id'); $correlation .=" and wanlshop_shop.shopname like '%{$filters['shopname']}%'"; } if(!empty($startDate)){ $starttime = strtotime($startDate); // $correlation .=" and wanlshop_groups.deliverytime >= {$starttime}"; } if(!empty($endDate)){ $endtime = strtotime($endDate) + 24 * 3600; // $correlation .=" and wanlshop_groups.deliverytime < {$endtime}"; } if(!empty($filters['status'])){ //$db::name('wanlshop_groups_order')->where()->column('id'); $correlation .=" and a.status = {$filters['status']}"; } // $shop_id = 41; $correlations = "sg.shop_id = {$shop_id} and o.deliveryDay >= {$starttime} and o.deliveryDay <= {$endtime}"; $GoodsModel = new \app\common\model\AgencyOrderGoods; $list = $GoodsModel->alias('a') // ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT') // ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT') // ->join('agency_goods_category agc','ag.cid = agc.id','LEFT') ->join('agency_order o','o.id = a.agency_order_id') ->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT') ->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT') ->join('wanlshop_category gc','sg.category_id = gc.id','LEFT') ->join('wanlshop_shop shop','sg.shop_id = shop.id') ->where($correlations) ->limit($offset, $limit) ->field('a.id,a.agency_order_id,a.number,a.price,a.groups_price,agency_shop_tax_rate,shop_tax_rate') ->field('gc.name as category_name') ->field('shop.id as shop_id,shop.shopname') ->field('gg.goods_id') ->field('sg.goods_unit_id,sg.title as goods_name') ->field('o.deliveryDay') ->order('o.deliveryDay asc,gc.weigh desc') // ->order('o.deliveryDay desc,agc.weigh desc') ->select(); // $result = $this->handleShopGoodsData($list); $count = $GoodsModel->alias('a') // ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT') // ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT') // ->join('agency_goods_category agc','ag.cid = agc.id','LEFT') ->join('agency_order o','o.id = a.agency_order_id') ->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT') ->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT') ->join('wanlshop_category gc','sg.category_id = gc.id','LEFT') ->join('wanlshop_shop shop','sg.shop_id = shop.id') ->where($correlations) ->field('a.id') ->order('o.deliveryDay asc,gc.weigh desc') // ->order('o.deliveryDay desc,agc.weigh desc') ->count(); $total = $GoodsModel->alias('a') // ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT') // ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT') // ->join('agency_goods_category agc','ag.cid = agc.id','LEFT') ->join('agency_order o','o.id = a.agency_order_id') ->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT') ->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT') ->join('wanlshop_category gc','sg.category_id = gc.id','LEFT') ->join('wanlshop_shop shop','sg.shop_id = shop.id') ->where($correlations) ->field('sum(a.number) as number,sum(a.number * a.price) as price') ->find(); $number = round($total['number'],1); $price = round($total['price'],2); $list = $this->handleShopGoodsData($list); $result = array("total" => $count, "rows" => $list, "number" => $number, "price" => $price); return json($result); } return $this->view->fetch(); } /** * 数据处理 * */ public function handleShopGoodsData($list) { $unit_list = \app\admin\model\wanlshop\GoodsUnit::column('id,title'); foreach($list as $k=>&$v){ $v['unit_name'] = empty($unit_list[$v['goods_unit_id']]) ? '-':$unit_list[$v['goods_unit_id']]; $v['deliveryDay_str'] = empty($v['deliveryDay']) ? '-':date('Y-m-d',$v['deliveryDay']); //进项税额 = 采购价/(1+进项税率)*进项税率 $item_shop_price = $v['groups_price']*$v['number']; // $total['groups_price'] = round(bcadd($total['groups_price'],$item_shop_price,2),2); $v['total_price'] = round($item_shop_price,2); $item_shop_invoice_price = 0; if(!empty($item_shop_price) && !empty($v['shop_tax_rate'])){ $item_shop_invoice_price = $item_shop_price/(1+$v['shop_tax_rate']/100)*$v['shop_tax_rate']/100; $item_shop_invoice_price = round($item_shop_invoice_price,2); } // $total['shop_invoice_price'] = round(bcadd($total['shop_invoice_price'],$item_shop_invoice_price,2),2); // $total['shop_invoice_price'] = $item_shop_invoice_price; } return $list; }优化下以上代码
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值