Yii Framework Forum: Need Help With Pdf Extension - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Need Help With Pdf Extension Rate Topic: ***** 1 Votes

#1 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 02:19 AM

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.
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 16 November 2012 - 03:46 AM

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
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 03:50 AM

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


In the view, access the model as normal:
<html>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <body>
        <div class="center"><h1><?= CHtml::encode($customer->name); ?>'s Member Card</h1></div>
 
...

0

#4 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 03:52 AM

View PostKonApaz, on 16 November 2012 - 03:46 AM, said:

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


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));
        $html2pdf->Output('MemberCard.pdf');
    }


but this 'Error 400 Your request is invalid.' appears. to be honest, I'm not sure what to do with this :(
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#5 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 03:54 AM

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.
0

#6 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:01 AM

View PostKeith, on 16 November 2012 - 03:54 AM, said:

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
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#7 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 16 November 2012 - 04:01 AM

View Postdyooolicious, on 16 November 2012 - 03:52 AM, said:

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));
        $html2pdf->Output('MemberCard.pdf');
    }


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



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)); :)
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#8 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:08 AM

View PostKonApaz, on 16 November 2012 - 04:01 AM, said:

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.
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#9 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 04:10 AM

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.
0

#10 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:14 AM

View PostKeith, on 16 November 2012 - 04:10 AM, said:

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
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#11 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 04:16 AM

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

#12 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 16 November 2012 - 04:17 AM

View Postdyooolicious, on 16 November 2012 - 04:08 AM, said:

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.



You said you are able to download pdf file. what is the content of this file?
the 'Error 400 Your request is invalid.' ?
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#13 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:19 AM

View PostKonApaz, on 16 November 2012 - 04:17 AM, said:

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:
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#14 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:19 AM

View PostKeith, on 16 November 2012 - 04:16 AM, said:

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


okay, I'll try
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#15 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 16 November 2012 - 04:25 AM

View Postdyooolicious, on 16 November 2012 - 04:19 AM, said:

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:


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:
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
1

#16 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:26 AM

View PostKeith, on 16 November 2012 - 04:16 AM, said:

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


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));
        $html2pdf->Output('MemberCard.pdf');
    }


can you tell me if there were any mistakes in there?
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#17 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:28 AM

View Postdyooolicious, on 16 November 2012 - 04:26 AM, said:

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));
        $html2pdf->Output('MemberCard.pdf');
    }


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
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#18 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 04:33 AM

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.
1

#19 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 16 November 2012 - 04:39 AM

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.
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#20 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 16 November 2012 - 04:41 AM

Can you post the view code where you're creating the link?
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users