我试图将array
值传递给collection.tpl文件。但它显示NULL
值。
但是在控制器中我写代码var_dump($this->data['collections']);
会在页面顶部显示一些数组值。结果如下
array(1){[0] => array(8){[“invoice_id”] => string(4)“1088”[“delivery_point_name”] => string(9)“Peelamedu”[“total”] => string(4)“1253”[“collection_amount”] => string(4)“1000”[“payment_type”] => string(7)“partial”[“payment_mode”] => string(4)“cash”[“status”] => string(4)“paid”[“datetime”] => string(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
。
这里错过了什么......?
提前致谢.... :)
答案 0 :(得分:0)
$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*/
}