我在控制器文件中有数组:
$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....
哪里有问题?
答案 0 :(得分:0)
我不知道你想做什么,但你可以在Opencart 2.x中通过controller
向view
发送变量$data
您可以通过以下方式发送$total_data
到tpl
文件:
$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'];
}
?>