繁体   English   中英

控制器数组值传递给opencart中的查看页面javascript脚本标记

[英]Controller array value pass to view page javascript script tag in opencart

我正在使用opencart 2.0.1.1,我正在从模型获取数据到控制器。 接下来,我需要通过脚本标签传递数据视图页面。 我已经做到了,但是它显示出令人毛骨悚然的问题。

(注意:在线将C:\\ xampp \\ www \\ htdocs \\ abc \\ catalog \\ view \\ theme \\ default \\ template \\ common \\ success.tpl中的数组转换为字符串)

在这方面的任何帮助将不胜感激。

控制器代码

success.php

    $this->load->model('checkout/order'); 
    $data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
    $data['ordertax'] = $this->model_checkout_order->gettax($this->session->data['order_id']);
    $data['orderProduct'] = $this->model_checkout_order->getOrderProduct($this->session->data['order_id']);
    $this->response->setOutput($this->load->view('default/template/common/success.tpl', $data));

查看代码

success.tpl

<script type="text/javascript">
  ga('require', 'ecommerce');
  ga('ecommerce:addTransaction', {
      'id': "<?php $orderDetails['order_id'];?>",                     // Transaction ID. Required. dynamic variable of order id
      'affiliation': "<?php $orderDetails['store_name'];?>",   // Affiliation or store name. Kuberan Silks
      'revenue': "<?php $orderDetails['total'];?>",               // Grand Total. grand total dynamic variable of the price
      'shipping':"<?php $ordertax['value'];?>" ,                  // Shipping. dynamic variable of shipping
      'tax': "<?php $orderProduct['tax'];?>"                     // Tax. dynamic tax variable
  });

  ga('ecommerce:addItem', {
      'id': "<?php $orderProduct['order_id'];?>",                     // Transaction ID. Required. 
      'name': "<?php $orderProduct['name'];?>",    // Product name. Required.
      'sku': "<?php $orderProduct['model'];?>",                 // SKU/code.
      //'category': 'Party Toys',         // Category or variation.
      'price': "<?php $orderProduct['price'];?>",                 // Unit price.
      'quantity':"<?php $orderProduct['quantity'];?>"                  // Quantity.
  });
  ga('ecommerce:send');
</script>
<?php echo $footer; ?>

每当我检查检查的元素时,它就会显示为:

<script type="text/javascript">
  ga('require', 'ecommerce');
  ga('ecommerce:addTransaction', {
      'id': "<b>Notice</b>: Undefined variable: orderDetails in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>41</b>",                     
      'affiliation': "<b>Notice</b>: Undefined variable: orderDetails in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>42</b>",   
  });

  ga('ecommerce:addItem', {
      'id': "<b>Notice</b>: Undefined variable: orderProduct in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>49</b>",                     
      'sku': "<b>Notice</b>: Undefined variable: orderProduct in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>51</b>",                 
  });
  ga('ecommerce:send');
</script>

数组到字符串的转换。

当您尝试在PHP中回显数组值时收到此错误。 您不能将数组用作字符串!!

要解决此问题,您可以将密钥添加到要打印的阵列。

例如。

<?php $orderDetails[0]['order_id'];?>

这将在键值为0的情况下返回$ orderDetails数组中order_id的值。建议您使用for循环从数组中获取值,因为您无法确定将有多少个键。

祝好运!!

暂无
暂无

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

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