繁体   English   中英

OpenCart PHP回调数组问题

[英]OpenCart PHP Callback Array Trouble

我正在尝试编写Netbanx API扩展,但是访问数组失败。 我在审讯时出现未定义索引的PHP错误。

数组转储为:

数组([transaction_status] =>成功[transaction_merchantRefNum] => 476 [id] => 271ZH271ZH271Z [transaction_amount] => 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);
    }

您非常正确地获得了这些警告!

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

因此你不能做

$_POST[1]

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

$_POST['transaction_merchantRefNum']

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM