zoukankan      html  css  js  c++  java
  • try cath用处

            if ($this->request->is('post')) {
                $products_id = $product['TradeProduct']['id'];
                $fee = $this->request->data('Trade.price');
                $bankCode = $this->request->data('Trade.bankCode');
                $pay_type = $this->request->data('Trade.payType');
                if ($this->request->data('Trade.swtich') != 1) {
                    $pay_type = 'shengpay-' . $this->Cashier->bankCode[$bankCode];
                }
                $subject = sprintf("用户充值(ecode-D%d-U%d)", $this->domainId, $users_id);
                try {
                    $order = $this->TradeOrder->make($users_id, $products_id, $fee, $pay_type, $subject);
                    if (false == $order) {
                        throw new CakeException('validationErrors');
                    }
                    $this->redirect(array(
                        'action' => 'ebank',
                        $order['TradeOrder']['id']
                    ));
                } catch (Exception $e) {
                    if ($e->getMessage() == 'validationErrors') {
                        //var_dump($this->TradeOrder->validationErrors);
                        if (isset($this->TradeOrder->validationErrors['pay_type'])) {
                            $this->error($this->TradeOrder->validationErrors['pay_type'][0]);
                        }
                        $this->redirect(array(
                            'action' => 'deposit'
                        ));
                    }
                }

    try cach解决的问题就是我以前不知道怎么做的,比如一个地方出错就不让下面执行下去了,就使用try

  • 相关阅读:
    12.数组三--数组的冒泡排序与快速排序
    11.数组二
    10.数组一
    Vue之组件与父子传值
    Django模型层
    面向对象的组合用法
    面向对象初识
    Python内置函数
    列表推导式,生成器表达式
    装饰器进阶
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/3030982.html
Copyright © 2011-2022 走看看