foreach使用openCart在collection.tpl文件中显示null



正在尝试将 array值传递给collection.tpl文件。但它显示NULL值。

但是在控制器中,我编写了代码var_dump($this->data['collections']);在页面顶部显示一些数组值。结果是follwing

array(1({[0] => array(8({[" Invoice_id"] => string(4(" 1088" [" verrive_point_name"] => string(9(" peelamedu" ["总计" [] =>字符串(4(" 1253" [" Collection_Amount"] =>字符串(4(" 1000" [" payay_type"] => string(7(" partial" [" payay_mode"] => string(4(现金" ["状态"] =>字符串(4("付费" [" dateTime"] =>字符串(19(" 2017-05-05 13:27:14"}}}

在这里我的代码: invoice.php

public function collection()
{
        $this->load->language('account/account');
        $data['breadcrumbs'] = array();
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Home'),
            'href' => $this->url->link('common/home')
        );
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Previous'),
            'href' => $this->url->link('account/invoice', '', 'SSL')
        );
        $this->load->model('account/add_invoice');
        //$data['action'] = $this->url->link('account/invoice/collection', '', 'SSL');
        $this->data['action'] = $this->url->link('account/invoice/collection', '', 'SSL');

       $invoiceId='';
        if(isset($_GET['invoice_id']))
        {
            $invoiceId=$_GET['invoice_id'];
        }
        $data['invoice']=array();

        $data['invoice_id']=$invoiceId;
        $data['products']=$this->getProduct();
        $data['units']=['Boxes','Pieces','Kg'];
        $data['delivery_point']=$this->getDeliveryPoint();
        $data['status']=['Enabled','Disabled'];

        $data['invoiceProduct']=$this->model_account_add_invoice->getProductByInvoiceId($invoiceId);
        $data['totalPriceData']=$this->model_account_add_invoice->getTotalPriceByInvoiceId($invoiceId);
        $invoiceDeliveryPointold=$this->model_account_add_invoice->getInvoiceDeliveryPoint($invoiceId);
        $query=$this->db->query("SELECT delivery_point_name,invoice_id FROM ".DB_PREFIX."invoice_delivery_point where invoice_id=".$invoiceId);
        $invoiceDeliveryPoint=$query->row['delivery_point_name'];
        $data['invoiceDeliveryPoint']=$invoiceDeliveryPoint;

        $query=$this->db->query("SELECT i.date_added,concat(c.firstname,' ',c.lastname) as name,c.tin_number,c.invoice_no_overwrite,i.invoice_id FROM ".DB_PREFIX."invoice i left join ".DB_PREFIX."customer c on i.customer_id=c.customer_id where i.invoice_id=".$invoiceId);
        $data['invoiceData']=$query->rows;
        $invoiceDeliveryPoint=$query->row['delivery_point_name'];
        $invoice_id = $query->row['invoice_id'];
         /*view collection*/
        $query22 = $this->db->query("select * from ".DB_PREFIX."collection where invoice_id='".$invoice_id."'");
        $show_collection = $query22->rows;
        foreach($show_collection as $collections)
        {
            $this->data['collections'][] = array(
                'invoice_id' => $collections['invoice_id'],
                'delivery_point_name' =>$collections['delivery_point_name'],
                'total' =>$collections['total'],
                'collection_amount' =>$collections['collection_amount'],
                'payment_type' =>$collections['payment_type'],
                'payment_mode' =>$collections['payment_mode'],
                'status' =>$collections['status'],
                'datetime' =>$collections['datetime']
                );
        }
        var_dump($this->data['collections']);
        /*view collection*/
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['column_right'] = $this->load->controller('common/column_right');
        $data['content_top'] = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer'] = $this->load->controller('common/footer');
        $data['header'] = $this->load->controller('common/header');
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/collection.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/collection.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/account/collection.tpl', $data));
        }
        /*Insert collection datas*/
        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {   
            $invoice_id = $_POST['invoice_id'];
            $delivery_point = $_POST['delivery_point'];
            $total = $_POST['total'];
            $collection_amount = $_POST['collection_amount'];
            $payment_type = $_POST['payment_type'];
            $payment_mode = $_POST['payment_mode'];
            $status = $_POST['status'];
            $query = $this->db->query("insert into ".DB_PREFIX."collection (invoice_id,delivery_point_name,total,collection_amount,payment_type,payment_mode,status,datetime) values('".$invoice_id."','".$delivery_point."','".$total."','".$collection_amount."','".$payment_type."','".$payment_mode."','".$status."',NOW())");
            //header("Location: index.php?route=account/invoice");
        }
        /*Insert collection datas*/
}

在我的 collection.tpl 我放置<?php var_dump($collections); ?>它显示NULL

这里错过了什么...?

预先感谢....:(

$this->data['collections'][]更改为 $data['collections'][]

public function collection()
        {
            $this->load->language('account/account');
            $data['breadcrumbs'] = array();
            $data['breadcrumbs'][] = array(
                'text' => $this->language->get('Home'),
                'href' => $this->url->link('common/home')
            );
            $data['breadcrumbs'][] = array(
                'text' => $this->language->get('Previous'),
                'href' => $this->url->link('account/invoice', '', 'SSL')
            );
            $this->load->model('account/add_invoice');
            $this->data['action'] = $this->url->link('account/invoice/collection', '', 'SSL');
            $invoiceId='';
            if(isset($_GET['invoice_id']))
            {
                $invoiceId=$_GET['invoice_id'];
            }
            $data['invoice']=array();

            $data['invoice_id']=$invoiceId;
            $data['products']=$this->getProduct();
            $data['units']=['Boxes','Pieces','Kg'];
            $data['delivery_point']=$this->getDeliveryPoint();
            $data['status']=['Enabled','Disabled'];

            $data['invoiceProduct']=$this->model_account_add_invoice->getProductByInvoiceId($invoiceId);
            $data['totalPriceData']=$this->model_account_add_invoice->getTotalPriceByInvoiceId($invoiceId);
            $invoiceDeliveryPointold=$this->model_account_add_invoice->getInvoiceDeliveryPoint($invoiceId);
            $query=$this->db->query("SELECT delivery_point_name,invoice_id FROM ".DB_PREFIX."invoice_delivery_point where invoice_id=".$invoiceId);
            $invoiceDeliveryPoint=$query->row['delivery_point_name'];
            $data['invoiceDeliveryPoint']=$invoiceDeliveryPoint;

            $query=$this->db->query("SELECT i.date_added,concat(c.firstname,' ',c.lastname) as name,c.tin_number,c.invoice_no_overwrite,i.invoice_id FROM ".DB_PREFIX."invoice i left join ".DB_PREFIX."customer c on i.customer_id=c.customer_id where i.invoice_id=".$invoiceId);
            $data['invoiceData']=$query->rows;
            $invoiceDeliveryPoint=$query->row['delivery_point_name'];
            $invoice_id = $query->row['invoice_id'];

             /*view collection*/
            $query22 = $this->db->query("select * from ".DB_PREFIX."collection where invoice_id='".$invoiceId."'");
            $show_collection = $query22->rows;
            foreach($show_collection as $collections)
            {
                $data['collections'][] = array(
                    'invoice_id' => $collections['invoice_id'],
                    'delivery_point_name' =>$collections['delivery_point_name'],
                    'total' =>$collections['total'],
                    'collection_amount' =>$collections['collection_amount'],
                    'payment_type' =>$collections['payment_type'],
                    'payment_mode' =>$collections['payment_mode'],
                    'status' =>$collections['status'],
                    'datetime' =>$collections['datetime']
                    );
            }
           /*view collection*/

            $data['column_left'] = $this->load->controller('common/column_left');
            $data['column_right'] = $this->load->controller('common/column_right');
            $data['content_top'] = $this->load->controller('common/content_top');
            $data['content_bottom'] = $this->load->controller('common/content_bottom');
            $data['footer'] = $this->load->controller('common/footer');
            $data['header'] = $this->load->controller('common/header');
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/collection.tpl')) {
                $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/collection.tpl', $data));
            } else {
                $this->response->setOutput($this->load->view('default/template/account/collection.tpl', $data));
            }
            /*Insert collection datas*/
            if ($this->request->server['REQUEST_METHOD'] == 'POST')
            {   
                $invoice_id = $_POST['invoice_id'];
                $delivery_point = $_POST['delivery_point'];
                $total = $_POST['total'];
                $collection_amount = $_POST['collection_amount'];
                $payment_type = $_POST['payment_type'];
                $payment_mode = $_POST['payment_mode'];
                $status = $_POST['status'];
                $query = $this->db->query("insert into ".DB_PREFIX."collection (invoice_id,delivery_point_name,total,collection_amount,payment_type,payment_mode,status,datetime) values('".$invoice_id."','".$delivery_point."','".$total."','".$collection_amount."','".$payment_type."','".$payment_mode."','".$status."',NOW())");
                //header("Location: index.php?route=account/invoice");
            }
            /*Insert collection datas*/
    }

相关内容

最新更新