I want to make a member card using pdf extension. I’m already install it successfully. but I’m getting confused with how to render it while sending the data.
this is my controller:
public function actionPdf() {
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML($this->renderPartial('pdf', array(/* what code I should give here? */), true));
$html2pdf->Output('MemberCard.pdf');
}
and this is my pdf.php:
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
<div class="center"><h1><?php //this should be the customer's name ?>'s Member Card</h1></div>
<br><br>
<table border="0" align="center">
<tr>
<td><img src="/home/prg3/pics/jedug.gif" width="200"></td>
<td>Id Customer<br>Nama Customer<br>Level Harga</td>
<td>:<br>:<br>:</td>
<td><?php //this should be the customer's id ?><br><?php //this should be the customer's name ?>
<br><?php //this should be the customer's level ?></td>
</tr>
</table>
</body>
</html>
help me please, with solving the question in my code above. thanks in advance.
Assuming that all of those fields are available in a customer model instance, you’d first get the instance in the action, then pass it into the view and use it there.
public function actionPdf() {
$customer = Customer::model()->someFindMethod();
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML(
$this->renderPartial('pdf', array('customer'=>$customer), true));
$html2pdf->Output('MemberCard.pdf');
}
If you’re using that syntax, you need to be sending the data in a GET parameter named ‘id’. If you’re using POST, you need to use Yii::app()->request->getPost(‘id’); instead of using a parameter to the method.
yes, it is rendered successfully. and I actually able to download my pdf file from that. I just have no idea, how to send the data along by rendering it.
The invalid request error occurs when the action’s parameters aren’t provided.
To send GET data, you send it as part of the URL. The simplest way to demonstrate is if you create a link, as this accounts for all of your URL rules and configuration. On another page, create this link:
no, when I’m not trying to send any data, it give me a blank form of member card. it contains no data from database of course. the error appears when I add the code that I give you before
I think you sould send data even that has no content. To understand better, could you tell me again please which part of your code has the problem and when?
Glad you got it working. To get the ID in the action, either put it back as a parameter or use Yii::app()->request->getQuery(‘id’); instead of $_GET[‘id’]. You’ll avoid PHP errors if the ID isn’t provided then.
hmm… last one question. when I change ‘id’=>1 with ‘id’=>$model->id_user, it doesn’t give me the user ID. I’ve tried to check it with firebug, and I see no user Id too in the link. how can I fix this?