Need Help With Pdf Extension

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));



and this is my pdf.php:


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


        <div class="center"><h1><?php //this should be the customer's name ?>'s Member Card</h1></div>


        <table border="0" align="center">


                <td><img src="/home/prg3/pics/jedug.gif" width="200"></td>

                <td>Id Customer<br>Nama Customer<br>Level Harga</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>





help me please, with solving the question in my code above. thanks in advance.

Hi dyooolicious

Acorrding to renderpartial document, in array parameter you could pass variables to the view (pdf.php in your case) file, for more dynamically content

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();


                $this->renderPartial('pdf', array('customer'=>$customer), true));



In the view, access the model as normal:


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


        <div class="center"><h1><?= CHtml::encode($customer->name); ?>'s Member Card</h1></div>



thanks for ur reply KonApaz.

I’m trying this one:

public function actionPdf($id) {

        $model = User::model()->findByPk($id);

        $html2pdf = Yii::app()->ePdf->HTML2PDF();

        $html2pdf->WriteHTML($this->renderPartial('pdf', array('model'=>$model), true));



but this ‘Error 400 Your request is invalid.’ appears. to be honest, I’m not sure what to do with this :(

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.

hi Keith,

from where I supposed to send the ‘data in a GET parameter named id’ ? thanks in advance

did you have created the view pdf file?

make sure that the view file render properly using Yii render like $this->render("pdf") and then check for the pdf issues by

$html2pdf->WriteHTML($this->renderPartial(‘pdf’, array(‘model’=>$model), true)); :)

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:

<?= CHtml::link('Get PDF', array('/controller/pdf', 'id'=>1)); ?>

Obviously, use the correct controller ID and ensure that the customer’s ID is valid - I’ve used 1 in the example.

When clicked, this will provide the value to the $id action parameter.

how about this one:

 array('label' => 'Download Member Card', 'url' => array('pdf', 'id'=>1)),

is it possible or not? thanks before

Start with the standard link. If it works, you can recreate it in any way you like.

You said you are able to download pdf file. what is the content of this file?

the ‘Error 400 Your request is invalid.’ ?

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 :mellow:

okay, I’ll try

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? :unsure:

hi Keith.

it still won’t work. this is my controller now:

public function actionPdf() {


        $model = User::model()->findByPk($_GET['id']);

        $html2pdf = Yii::app()->ePdf->HTML2PDF();

        $html2pdf->WriteHTML($this->renderPartial('pdf', array('model'=>$model), true));



can you tell me if there were any mistakes in there?

oops, sorry. I forgot that I don’t have Id number 1. LOL

it works now. thanks ;D

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?

thanks in advance.

Can you post the view code where you’re creating the link?