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

posted @ 2013-04-19 16:20  linksgo2011  阅读(273)  评论(0编辑  收藏  举报