我正在研究yii2
框架。我正在pdf
使用kartik\mpdf\Pdf
. 有一个名为subdivision
我想在pdf
文件头上打印的字段。
$sql_r = "SELECT DISTINCT ogph.`id` AS 'OGP_Serial_No',DATE(ogph.`created_at`) AS 'Date',uu.`name` AS 'Created_By',ogpd.`meter_serial` AS 'Meter_Serial_Number', u.`name` AS 'Issued_To', ps.`name` AS 'Store',sd.`name` AS 'Sub_Division',
IFNULL(ogph.`admin_incharge`,'') AS 'Admin_Incharge', IFNULL(ogph.`project_manager`,'') AS 'Project_Manager', IFNULL(ogph.`driver_name`,'') AS 'Driver_Name', IFNULL(ogpd.`remarks`,'') AS 'Remarks'
FROM `ogp_header` ogph
INNER JOIN `ogp_detail` ogpd ON ogph.`id` = ogpd.`ogp_id`
INNER JOIN `user` u ON ogph.`issuer` = u.`id`
INNER JOIN `user` uu ON ogph.`created_by` = uu.`id`
INNER JOIN `survey_hesco_subdivision` sd ON ogph.`sub_division` = sd.`sub_div_code`
INNER JOIN `project_store` ps ON ogph.`store_id` = ps.`id` $where AND ogph.`id` = $ogp_id";
$sql_r = $sql_r . " LIMIT " . $from . " OFFSET " . $to;
$dataProvider = new SqlDataProvider([
'sql' => $sql_r,
'pagination' => false
]);
$content = $this->renderPartial('view_pdf_ogp', ['dataProvider' => $dataProvider]);
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
// A4 papr format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
'cssInline' => '.kv-heading-1{font-size:14px}',
// set mPDF properties on the fly
'options' => ['title' => 'OGP Document'],
// call mPDF methods on the fly
'methods' => [
'SetHeader' => ['Name.||Generated On: ' . date("Y-m-d h:i:sa")],
'SetFooter' => ['{PAGENO}']
]
]);
在上面的代码中,我想做类似的事情'SetHeader' => ['Accurate (PVT) LTD.|Sub-Division: Here I want to print the sub division name|Generated On: ' . date("Y-m-d h:i:sa")],
我试过什么?
我试图通过添加来做到这一点
'SetHeader' => ['Name.|Sub-Division: '.<?php $model=$dataProvider->getModels()[0]; print_r($model['Sub_Division'])?>.'|Generated On: ' . date("Y-m-d h:i:sa")]
并且
'SetHeader' => ['Name.|Sub-Division: '.$content->Sub_Division.'|Generated On: ' . date("Y-m-d h:i:sa")],
但是两者都给了我non-object
错误。有什么方法可以将字符串放在从查询中获取的标题上?
任何帮助将不胜感激。