<?php
/* @property phpword_model $phpword_model */
include_once(APPPATH."third_party/PhpWord/Autoloader.php");
include_once(APPPATH."core/Front_end.php");
use PhpOffice\PhpWord\Autoloader;
use PhpOffice\PhpWord\Settings;
Autoloader::register();
Settings::loadConfig();
class Phpword extends Front_end {
function __construct(){
parent::__construct();
$this->load->model('phpword_model');
}
public function download() {
$this->load->library('Phpword');
//$news = $this->phpword_model->get_news();
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('application/third_party/PhpWord/resources/informe.docx');
$year = date('Y', strtotime('now'));
$month = date('m', strtotime('now'));
$monthName = date('F', mktime(0, 0, 0, $month, 10));
$day = date('d', strtotime('now'));
$filename = 'INF Nº NUMBER-'.$year.'InformeCodeigniter'. $monthName.'.docx';
$templateProcessor->setValue('year', $year);
$templateProcessor->setValue('month', $monthName);
$templateProcessor->setValue('day', $day);
$templateProcessor->saveAs($filename);
// send results to browser to download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
flush();
readfile($filename);
unlink($filename); // deletes the temporary file
exit;
}
}