<a href="<?php echo \General::getURIforDownload('mycontroller'); ?>">Download CSV file</a>
<?php
namespace app\controller;
class MyController extends \AppController {
static protected function action_download() {
$response = new \Response();
$header = array('Column 1','Column 2','Column 3');
$data = array(
array('Row 1 col. 1','Row 1 col. 2','Row 1 col. 3'),
array('Row 2 col. 1','Row 2 col. 2','Row 2 col. 3'),
array('Row 3 col. 1','Row 3 col. 2','Row 3 col. 3'),
);
$response->setDataForCsv($data, 'myfile.csv', $header);
return $response;
}
}
<?php
namespace controller;
class MyPdfController extends \AppController {
static protected function action_download() {
$request = new \Request();
$myValue = $request->my_value;
// FPDF is installed in the applications/default/app/fpdf directory
require('app' . DIRECTORY_SEPARATOR.'fpdf'.DIRECTORY_SEPARATOR.'fpdf.php');
$pdf = new \FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,"PDF document generated from ZnetDK, value: $myValue");
// Response returned to the user's web browser
$response = new \Response();
$response->setPrinting($pdf, 'mygenerateddoc.pdf');
return $response;
}
}
<a href="<?php echo \General::getURIforDownload('mypdfcontroller','my_value=Hello');?>">PDF Printing...</a>
static protected function action_download() {
$response = new \Response();
$header = array('Part number','Name','Description','Price');
$productsDAO = new \app\model\ProductsDAO();
while($row = $productsDAO->getResult()) {
$data[] = array($row['part_number'],$row['name'],$row['description'],
\Convert::toMoney($row['price'], FALSE, 2));
}
$response->setDataForCsv($data, 'myfile.csv', $header);
return $response;
}
static protected function action_download() {
$response = new \Response();
// FPDF is installed in the applications/default/app/fpdf directory
require('app' . DIRECTORY_SEPARATOR.'fpdf'.DIRECTORY_SEPARATOR.'fpdf.php');
$pdf = new \FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'List of products',0,1,'C');
$pdf->Ln(2);
$productsDAO = new \app\model\ProductsDAO();
while($row = $productsDAO->getResult()) {
$pdf->SetFont('Arial','B',12);
$pdf->Cell(0,5,$row['part_number'] . ' - ' . $row['name'],0,1);
$pdf->SetFont('Arial','I',11);
$pdf->Cell(140,5,$row['description'],'B');
$pdf->SetFont('Arial','',12);
$pdf->Cell(0,5,\Convert::toMoney($row['price'],FALSE),'B',1,'R');
$pdf->Ln(2);
}
$response->setPrinting($pdf, 'products.pdf');
return $response;
}
<form id="dynpdfwithform" class="zdk-form">
<label>My value</label>
<input name="myvalue" required>
<button class="zdk-bt-save" type="submit">Generate PDF</button>
</form>
<script>
$(function() {
$('#dynpdfwithform').zdkform({
complete: function () {
var formData = $(this).zdkform('getFormData');
window.open("<?php echo \General::getURIforDownload('mypdfcontroller'); ?>"
+ "&my_value=" + formData[0].value, '_blank');
}
});
});
</script>
<?php
namespace controller;
class MyPdfController extends \AppController {
static protected function action_download() {
$request = new \Request();
$myValue = $request->my_value;
// FPDF is installed in the applications/default/app/fpdf directory
require('app' . DIRECTORY_SEPARATOR.'fpdf'.DIRECTORY_SEPARATOR.'fpdf.php');
$pdf = new \FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,"PDF document generated from ZnetDK, value: $myValue");
// Response returned to the user's web browser
$response = new \Response();
$response->setPrinting($pdf, 'mygenerateddoc.pdf');
return $response;
}
}