DOMPDF在数组内部循环

时间:2018-10-20 01:42:03

标签: dompdf

我有这个数据数组。

private $form = array(
'payslip'=>'
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body style="font-size:12px;">
<div class="row">
    <div class="col-xs-2 text-center">
        <img src="assets/img/logo.png" alt="user" class="img-thumbnail" />
    </div>
    <div class="col-xs-5">
        <div class="row">
            <div class="col-xs-12 text-center">
                <p style="font-weight: 700;margin: 0;font-size: 16px;">PAY STATEMENT</p>
                <p>{@date_from} - {@date_to}</p>
            </div>
        </div>
    </div>
    <div class="col-xs-1">
        <div class="row">
            <div class="col-xs-12 text-right">
                <p style="margin: 0;">Date:</p>
                <p style="margin: 0;">ID #:</p>
                <p style="margin: 0;">Fullname:</p>
            </div>
        </div>
    </div>
    <div class="col-xs-2">
        <div class="row">
            <div class="col-xs-12 text-right" style="margin: 0;">
                <p style="margin: 0;">{@date}</p>
                <p style="margin: 0;">{@barcode}</p>
                <p style="margin: 0;">{@fullname}</p>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin-top: 10px;">
    <div class="col-xs-2">
        <div class="text-muted">Basis</div>
        <p>{@basis}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Overtime</div>
        <p>{@overtime}</p>
    </div>
    <div class="col-xs-2">
        <div class="text-muted">SSS</div>
        <p>{@sss}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Taxable</div>
        <p>{@taxable}</p>
    </div>
</div>
<div class="row">
    <div class="col-xs-2">
        <div class="text-muted">No. of days</div>
        <p>{@no_of_days}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">SSS Loan</div>
        <p>{@sss_loan}</p>
    </div>
    <div class="col-xs-2">
        <div class="text-muted">Late</div>
        <p>{@late}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Absent</div>
        <p>{@absent}</p>
    </div>
</div>
<div class="row">
    <div class="col-xs-2">
        <div class="text-muted">De Minimis</div>
        <p>{@de_minimis}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">No of hour</div>
        <p>{@hours}</p>
    </div>
    <div class="col-xs-2">
        <div class="text-muted">Philhealth</div>
        <p>{@philhealth}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Coop</div>
        <p>{@coop}</p>
    </div>
</div>
<div class="row">
    <div class="col-xs-2">
        <div class="text-muted">Meal Allowance</div>
        <p>{@meal}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Holiday</div>
        <p>{@holiday}</p>
    </div>
    <div class="col-xs-2">
        <div class="text-muted">Pag-ibig</div>
        <p>{@pagibig}</p>
    </div>
    <div class="col-xs-3">
        <div class="text-muted">Pag-ibig Loan</div>
        <p>{@pagibig_loan}</p>
    </div>
</div>
<div class="row">
    <div class="col-xs-3">
        <p style="font-weight: 700;margin: 0;">NET PAY</p>
        <p>{@net_pay}</p>
    </div>
    <div class="col-xs-4">
        <p style="font-weight: 700;margin: 0;">TOTAL EARNINGS</p>
        <p>{@total_earnings}</p>
    </div>
    <div class="col-xs-4">
        <p style="font-weight: 700;margin: 0;">TOTAL DEDUCTION</p>
        <p>{@total_deduction}</p>
    </div>
</div>
</body>
</html>',
'loa'=>'
<html>
<body style="font-size:16px;">
<div style="text-align:center;"><img src="assets/img/logo-big.png" style="width:50%;" /></div>
<div style="height:40px;"></div>
<div style="text-align:center;padding:15px;background:#aa3333;"><strong style="color:#fff;font-size:42px;">LETTER of ACCEPTANCE</strong></div>
<div style="padding:20px;padding-top:40px;">
    <div><strong>Date of Issue : </strong><u>{@date}</u></div>
    <div><strong>Name : </strong><u>{@name}</u> ({@address})</div>

    <p style="padding-top:20px;">Dear {@name}</p>
    <p>
        Good day!<br />
        We are writing to formally inform you that you are officially admitted to English Fella Educational Corporation. We are pleased that you have chosen our school where you can improve your English proficiency.<br />
        Upon your arrival, everything is prepared for you so there is nothing to worry about. In order to make your stay worth it and memorable, our staff is very much willing to help you anytime.<br />
        Below is relevant information about you. Please notify us for some corrections.
    </p>
    <p>
        <ul>
            <li>Name : {@name}</li>
            <li>Gender : {@gender}</li>
            <li>Nationality : {@nationality}</li>
            <li>D. O. B : {@dob}</li>
            <li>Course : {@course}</li>
            <li>Study Period : {@period}Weeks</li>
        </ul>
    </p>
    <p>
        Should you have other concerns regarding your admission, please message us as soon as possible.<br />
        We look forward to giving you the best service.<br />
        Gongratulations and see you!
    </p>
    <p style="padding-top:20px;">Sincerely yours,</p>
    <p>
        Jaychell A. Redilosa<br />
        Head Teacher<br />
        Academic Department
    </p>
    <p style="padding-top:50px;">
        <span style="font-size:10px;">English Fella Campus 1 : Sitio Highway 11, Brgy Talamban, Cebu city, Philippines / TEL +63-32-52-3274 / FAX +63-32-343-3871</span><br />
        <span style="font-size:10px;">English Fella Campus 2 : Tigbao, Brgy Talamban, Cebu city, Philippines / TEL +63-32-344-0881 / FAX +63-32-344-0419</span>
    </p>
</div>
</body>
</html>'
);

这是我想使用DOMPDF加载的html表单数组,$form['loa]是一个,所以很容易,但是$form['payslip']却是一个循环,大量数据,如何在数据数组上循环加载?

public function generate($in_campus) {

    $this->load->model('salary_model');
    $this->load->model('staff_model');

    $items = $this->salary_model->getStaffSalary(array('ns_staff.nationality'=>'FILIPINO', 'ns_staff.campus'=>$in_campus), 'department ASC');
    // $item = $this->salary_model->selectItem(array('idx'=>1));
    // $item = $this->staff_model->selectItem(array('idx'=>1));

    $replace = array('{{@fullname}}', '{{@barcode}}', '{{@date}}', '{{@date_from}}', '{{@date_to}}', '{{@basis}}');
    $new = array($items[0]->fullname, $items[0]->barcode, date('Y-m-d'), date('F d, Y', strtotime($items[0]->date_from)), date('F d, Y', strtotime($items[0]->date_to)), number_format($items[0]->salary_amount / 2, 2));

    $form = ob_get_clean();
    $this->dompdf = new DOMPDF();
    $this->dompdf->load_html(preg_replace($replace, $new, $this->form['payslip']));
    $this->dompdf->render();
    $this->dompdf->stream("test.pdf", array('Attachment'=>0));
}

这是我制作的用于生成数据的函数,但是很难将其循环使用吗?我只是将[0]放在了一对一的测试中,但是当有大量数据时,尤其是在表单只有一个的情况下,我发现它很难。

0 个答案:

没有答案