从控制器OpenCart中的数组中获取数据

时间:2016-11-17 13:46:41

标签: arrays opencart

我在控制器文件中有数组:

$total_data = array();

                $totals = $this->model_sale_order->getOrderTotals($order_id);

                foreach ($totals as $total) {
                    $total_data[] = array(
                        'title' => $total['title'],
                        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
                    );
                }

如何在同一控制器文件中传递'text'? 例如:$text = $total['text'];我收到错误undefined index: text in.... 哪里有问题?

1 个答案:

答案 0 :(得分:0)

我不知道你想做什么,但你可以在Opencart 2.x中通过controllerview发送变量$data

您可以通过以下方式发送$total_datatpl文件:

$data['total_data'] = $total_data;

因此您的代码必须是:

$total_data = array();

$totals = $this->model_sale_order->getOrderTotals($order_id);

foreach ($totals as $total) {
    $total_data[] = array(
        'title' => $total['title'],
        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value'])
    );
}

$data['total_data'] = $total_data;

并在view(tpl文件)中使用它:

<?php 
    foreach($total_data as $total){
        echo $total['text']; 
    }
?>