有什么办法可以在codeigniter中获得3份发票?

时间:2019-07-11 04:27:04

标签: codeigniter phpmyadmin

我正在尝试在codeigniter中打印3份发票。我已经完成了获取发票pdf文件的方法。有什么方法可以获取以普通html格式打印的3份发票?当我单击“以pdf格式查看”时,我通过单击“视图”和pdf版本获取普通的html进行了尝试

我的观点:

    <?php include('admin_header.php');?>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <div class="container box">
            <br />
        <h3 align="center">Invoice List</h3><br />
        <br />  
        <?php
        if(isset($customer_data))
        {
        ?>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <tr>
                <th>Invoice ID</th>
                <th>Customer Name</th>
                <th>Customer Phone Number</th>
                <th>Customer Billing Address</th>
                <th>Customer Shipping Address</th>
                <th>Computer Serial Number</th>
                <th>Computer Manufacturer</th>
                <th>Computer Model</th>
                <th>Computer Configuration</th>
                <th>Monthly Hire Rate</th>
                <th>Total Hire Rate</th>
                <th>View</th>
                <th>View in PDF</th>
            </tr>
         <?php
            foreach($customer_data->result() as $row)
            {
              echo '
                 <tr>
                 <td>'.$row->invoice_id.'</td>
                 <td>'.$row->cus_name.'</td>
                 <td>'.$row->cus_phone.'</td>
                 <td>'.$row->cus_badr.'</td>
                 <td>'.$row->cus_sadr.'</td>
                 <td>'.$row->com_sno.'</td>
                 <td>'.$row->com_make.'</td>
                 <td>'.$row->com_model.'</td>
                 <td>'.$row->com_config.'</td>
                 <td>'.$row->mohr.'</td>
                 <td>'.$row->tohr.'</td>
                 <td><a href="'.base_url(). 'htmltopdf/details/'.$row->invoice_id.'">View</a></td>
                 <td><a href="'.base_url(). 'htmltopdf/pdfdetails/'.$row->invoice_id.'">View in PDF</a></td>
                 </tr>
              ';
            }
          }
          ?>
        </table>    
    </div>
    <?php
    {
        if(isset($customer_details))
    {
       echo $customer_details;
    }
    }
    ?>
    </div>
    </body>
    </html>

我的控制器:

    <?php
    class HtmltoPDF extends MY_Controller
    {
        public function __construct()
        {
            parent::__construct();
            $this->load->model('htmltopdf_model');
            $this->load->library('pdf');
        }
    public function index()
    {
        $this->load->helper('form');
        $data['customer_data']=$this->htmltopdf_model->fetch();
        $this->load->view('admin/htmltopdf',$data);
    }
    public function details()
    {
        if($this->uri->segment(3))
        {
            $invoice_id=$this->uri->segment(3);
            $data['customer_details']=$this->htmltopdf_model->fetch_single_details($invoice_id);
            $this->load->view('admin/htmltopdf',$data);
        }
    }
        public function pdfdetails()
        {
            if($this->uri->segment(3))
        {
            $invoice_id=$this->uri->segment(3);
            $html_content='<h3 align="center">Invoice List</h3>';
            $html_content .= $this->htmltopdf_model->fetch_single_details($invoice_id);
            $this->pdf->loadHtml($html_content);
            $this->pdf->render();
            $this->pdf->stream("".$invoice_id."pdf", array("Attachment"=>0));
    }
    }
    }

我的模特:

    <?php
    class Htmltopdf_model extends CI_Model
    {
    public function fetch()
    {
        $this->db->order_by('invoice_id','DESC');
        return $this->db->get('invoice');
    }
    public function fetch_single_details($invoice_id)
    {
        $this->db->where('invoice_id',$invoice_id);
        $data=$this->db->get('invoice');
        $output='<table width="100%" cellspacing="5" cellpadding="5">';
        foreach ($data->result() as $row) 
        {
            $output .='
            <tr>
            <td width="100%">
            <p><b>Name : </b>'.$row->cus_name.'</p>
            <p><b>Phone: </b>'.$row->cus_phone.'</p>
            <p><b>Address: </b>'.$row->cus_sadr.'</p>
            </td>
            </tr>
            ';
        }
        $output .='
        <tr>
            <td colspan="2" align="center"><a href="'.base_url().'htmltopdf" class="btn btn-primary">Back</a></td>
        </tr>
        ';
        $output .='</table>';
        return $output;
    }
    }
    ?>

1 个答案:

答案 0 :(得分:0)

用于生成PDF

 $invoice_id=$this->uri->segment(3);
 $html_content='<h3 align="center">Invoice List</h3>';
 $html_content .= $this->htmltopdf_model->fetch_single_details($invoice_id);
 // 3 pages of same content means three times $html_content concatenated 
 $this->pdf->loadHtml($html_content.$html_content.$html_content);

用于HTML视图

if($this->uri->segment(3))
    {
        $invoice_id=$this->uri->segment(3);
        $data['customer_details']=$this->htmltopdf_model->fetch_single_details($invoice_id);

        // Load the view 3 times
        $this->load->view('admin/htmltopdf',$data);
        $this->load->view('admin/htmltopdf',$data);
        $this->load->view('admin/htmltopdf',$data);
    }

或者,您可以使用“ for {}循环”将页面内容重复3次。