codeigniter生成多个pdf

时间:2016-06-14 06:42:12

标签: codeigniter pdf-generation dompdf

我试图在循环中针对成员ID生成pdf,但每次我只得到第一个,我在foreach中添加了代码,因此它运行了多次,但它只给了我一个pdf.please有人帮助我

public function pdf($ids){

    $k = 0;
    foreach ($ids as $key => $id) {


    $data[$k]['academics'] =  $this->Utility_model->get_all_from_table_where('member_academics', array('member_id' => $id));
    $data[$k]['member_employment'] =  $this->Utility_model->get_all_from_table_where('member_employment', array('member_id' => $id));
    $data[$k]['member_data'] = $this->Utility_model->get_all_from_table_where('members',array('member_id' => $id));
    $data[$k]['disclosure'] = $this->Utility_model->get_all_from_table('generalsettings',array('key'=>'disclosure'));
    $data[$k]['enrollment_fee'] = $this->Utility_model->get_all_from_table('member_invoices',array('user_id' => $id,'paymentFor'=>'Enrollment Fee'));
    $data[$k]['enrollment_fee']['payment'] = $this->Utility_model->get_all_from_table('member_payments',array('invoice_id'=>$data[$k]['enrollment_fee']['id']));

    $j=0;
    if (!empty($data[$k]['member_data'])) {
        foreach ($data[$k]['member_data'] as $member) {
            $data[$k]['member_data'][$j]['term'] = $this->Utility_model->get_all_from_table('term', array('term_id' => $member['term_id']));
            $data[$k]['member_data'][$j]['degree'] = $this->Utility_model->get_all_from_table('degree', array('degree_id' => $member['degree_id']));
             $data[$k]['member_data'][$j]['year'] = $this->Utility_model->get_all_from_table('year', array('year_id' => $member['year_id']));
             $data[$k]['member_data'][$j]['address'] = $this->Utility_model->get_all_from_table('member_addresses', array('id' => $member['address_id']));

            $j++;
        }
    }

    $this->load->view('admin/reports_management/applications_pdf/pdf_output',$data[$k],false);
    $html = $this->output->get_output();

    $this->load->library('dompdf_gen');
    $this->dompdf->load_html($html);
    $this->dompdf->render();
    $this->dompdf->stream($k."file".".pdf");
    $k++;   
    }
    // echo "<pre>";
    // print_r($data);
    // die;
}

1 个答案:

答案 0 :(得分:0)

只要您只是请求页面一旦无法获得控制器方法输出多个文件。您可以尝试制作多页PDF或者您需要更改控制器的调用方式,并多次调用它。

有关制作多页PDF的一些信息,请参阅此答案:How to create several pages with dompdf