当我将它调用到另一个方法 - PHP时,我的方法不会加载

时间:2017-05-23 05:42:46

标签: php slim

我不知道为什么我的方法在加载到其他方法时不起作用..它没有给出任何PHP错误,所以我不知道在哪里&如何调试.. 你体验过这个吗?

这是我的代码..

这是我想要加载其他方法的方法

    public function show($request, $response){

    $status = $request->getParam('status');
    $refno = $request->getParam('refno');
    $msg = urldecode($request->getParam('message'));
    $refx = explode(' ', $msg);

    do {
        // $reference_number = $this->randomlib->generateString(20, '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ');
        $reference_number = $this->randomlib->generateString(5, '0123456789'); //transaction id for dragonpay
        $reference_number_exist = $this->db->table('order_payment')->where('reference_number', $reference_number)->exists();
    } while ($reference_number_exist === true);     

    switch ($request->getParam('status')) {
        case 'S':
            return $this->view->render($response, 'portal/dragonpay-success/view.twig',[
                'refno' => $refno,
                'status' => $status,
                'message' => $refx[4]
            ]);
            $this->DragonpayPayment($request, $response, $reference_number);
            break;
        case 'P':
            return $this->view->render($response, 'portal/dragonpay-pending/view.twig',[
                'status' => $status,
                'refno' => $refno
            ]);
            break;
        case 'F':
            return $this->view->render($response, 'portal/dragonpay-failed/view.twig',[
                'refno' => $refno,
                'status' => $status,
                'message' => $msg
            ]);
            break;                              
    }

}

这是我想要加载的方法

    public function DragonpayPayment($request, $response, $reference_number){

    $amount = '';

    //insert transaction in db
    $transaction = $this->auth->user()->order()->create([
        'order_type_id' => $this->db->table('sys_mf_order_type')->where('order_type_name', 'add-balance')->first()->order_type_id,
        'store_id'      => $this->schoolAdmin->getStoreAdministratorDetail('store_id'),
        'status'        => 'completed',
        'order_for_id'  => 0,
        'remarks'       => 'Load-up DragonPay',
        'school_id'     => $this->schoolAdmin->school_id
    ]);

    $transaction->orderPayment()->create([
        'payment_type'     => 'DragonPay',
        'amount'           => $amount,
        'reference_number' => sha1($reference_number),
        'school_id'        => $this->school->school_id
    ]);

}

它没有给出任何错误,所以我不知道如何调试它,提前感谢!

2 个答案:

答案 0 :(得分:0)

  

对于PHP中的错误调试,请在方法

中使用此代码
var_dump('variable data');die();
  

OR

print_r('varible data');die();

答案 1 :(得分:0)

您至少遇到一个问题:DragonpayPayment()部分对case 'S'的来电是unreachable statement,因为它在return声明后发现自己。

return $this->view->render(/*...*/);
$this->DragonpayPayment($request, $response, $reference_number);

写:

$this->DragonpayPayment($request, $response, $reference_number);
return $this->view->render(/*...*/);

另外:仅使用while语句,而不是do-while。另外......你的do-while在你的形式中毫无意义。 删除它,然后改为编写变量:

// $reference_number = $this->randomlib->generateString(20, '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ');
$reference_number = $this->randomlib->generateString(5, '0123456789'); //transaction id for dragonpay
$reference_number_exist = $this->db->table('order_payment')->where('reference_number', $reference_number)->exists();

并使用

switch ($status) {...}

而不是

switch ($request->getParam('status')) {...}

编辑1:

尝试使用基本的异常处理。因此,DragonpayPayment()将代码封装在try-catch块中:

public function DragonpayPayment($request, $response, $reference_number) {
    try {
        $amount = '';

        //insert transaction in db
        $transaction = $this->auth->user()->order()->create([
            'order_type_id' => $this->db->table('sys_mf_order_type')->where('order_type_name', 'add-balance')->first()->order_type_id,
            'store_id' => $this->schoolAdmin->getStoreAdministratorDetail('store_id'),
            'status' => 'completed',
            'order_for_id' => 0,
            'remarks' => 'Load-up DragonPay',
            'school_id' => $this->schoolAdmin->school_id
        ]);

        $transaction->orderPayment()->create([
            'payment_type' => 'DragonPay',
            'amount' => $amount,
            'reference_number' => sha1($reference_number),
            'school_id' => $this->school->school_id
        ]);
    } catch (Exception $exception) {
        echo '<pre>' . print_r($exception, true) . '</pre>';
        exit();
    }
}

再跑一遍。