Monday, December 1, 2008

Re: TCPDF and Cake PHP

You might try and remove "echo" from your last line of code and leave
it as: $tcpdf->Output('filename.pdf', 'D');
I don't know how your routes are set up but you might try
127.0.0.1/cake/myapp/teacher/viewpdf/1 - you are missing the action
from your url.

On Dec 1, 10:34 pm, Fernando Mendonça <fernand...@gmail.com> wrote:
> Hi everybody,
>
> I'm trying to generate some pdfs files with Cake PHP and TCPDF with
> Bakery Tutorial of this address:http://bakery.cakephp.org/articles/view/creating-pdf-files-with-cakep...
>
> I did everything like this tutorial and I wrote in one of my
> controller (teacher_controller.php) the follow code:
>
>         function __view($id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid Teacher.', true));
>                         $this->redirect(array('action'=>'index'));
>                 }
>
>                 $this->set('teacher', $this->Teacher->read(null, $id));
>
>         }
>
>         function viewPdf($id = null)
>     {
>         if (!$id)
>         {
>             $this->Session->setFlash('Sorry, there was no property ID
> submitted.');
>             $this->redirect(array('action'=>'index'), null, true);
>         }
>         //Configure::write('debug',0); // Otherwise we cannot use this
> method while developing
>
>         $id = intval($id);
>
>         $property = $this->__view($id); // here the data is pulled
> from the database and set for the view
>
>         if (empty($property))
>         {
>             $this->Session->setFlash('Sorry, there is no property with
> the submitted ID.');
>             $this->redirect(array('action'=>'index'), null, true);
>         }
>
>         $this->layout = 'pdf'; //this will use the pdf.ctp layout
>         $this->render();
>     }
>
> I created the view (viewPdf.ctp) too:
>
> <?php
> App::import('Vendor','xtcpdf');
> $tcpdf = new XTCPDF();
> $textfont = 'freesans'; // looks better, finer, and more condensed
> than 'dejavusans'
>
> $tcpdf->SetAuthor("KBS Homes & Properties athttp://kbs-properties.com");
> $tcpdf->SetAutoPageBreak( false );
> $tcpdf->setHeaderFont(array($textfont,'',40));
> $tcpdf->xheadercolor = array(150,0,0);
> $tcpdf->xheadertext = 'KBS Homes & Properties';
> $tcpdf->xfootertext = 'Copyright © %d KBS Homes & Properties. All
> rights reserved.';
>
> // Now you position and print your page content
> // example:
> $tcpdf->SetTextColor(0, 0, 0);
> $tcpdf->SetFont($textfont,'B',20);
> $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
> // ...
> // etc.
> // see the TCPDF examples
>
> echo $tcpdf->Output('filename.pdf', 'D');
>
> ?>
>
> But when I try to acess: 127.0.0.1/cake/myapp/teacher/1 the message
> "Sorry, there is no property with the submitted ID." appears. I know
> this message has to appears when nothing is set to $property, but I
> thing I'm doing this.
>
> Anybody Can help me?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: