【问题标题】:OpenCart PHP Callback Array TroubleOpenCart PHP回调数组问题
【发布时间】:2014-08-22 09:23:16
【问题描述】:

我正在尝试编写 Netbanx API 扩展,但访问阵列失败。 我在询问时收到未定义索引的 PHP 错误。

数组转储是:

数组 ( [transaction_status] => 成功 [transaction_merchantRefNum] => 476 [id] => 271ZH271ZH271Z [交易金额] => 4200)

我的回调函数是:

public function callback() {
    $this->language->load('payment/netbanx_payments');
    $this->load->model('checkout/order');   
    $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
    $this->log->write(print_r($_POST, 1)); //FOR DEBUGGING        
    if(isset($_POST['transaction_merchantRefNum'])){
        $orderId = $_POST['transaction_merchantRefNum'];
        if(in_array($orderId, $_POST)){
                $message = '';

                if (isset($_POST[1])) { 
                    $message .= 'transaction_merchantRefNum: ' . $_POST[1] . "\n";
                }

                if (isset($_POST[3])) {
                    $message .= 'transaction_amount: ' . $_POST[3] . "\n";
                }

                if (isset($_POST[2])) {
                    $message .= 'id: ' . $_POST[2] . "\n";
                }

                if ($_POST[0] == 'success') {
                    $this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('netbanx_payments_order_status_id'), $message, false);
                } else {
                    $this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('config_order_status_id'), $message, false);
                }

                $this->redirect($this->url->link('checkout/success'));
                                unset($myarray);
    }

【问题讨论】:

    标签: php arrays callback opencart netbanx-api


    【解决方案1】:

    您收到的警告非常正确!

    在您的代码中,您正在访问 $_POST 索引,因为它们是数字,但它们不是。

    你不能这样做

    $_POST[1]
    

    如果您的 POST 数组只有字符串索引,那么您必须这样做

    $_POST['transaction_merchantRefNum']
    

    在 OpenCart 中,我建议使用您手头的库,因此不要直接访问 $_POST,而是通过系统库访问它,即 $this->request->post

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      相关资源
      最近更新 更多