-1

こんにちは、cakephp にある TCPDF マニュアルを使用しようとしています。

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

しかし、私のシステムではまったく機能していません。私はそこで正確な手順に従いました...

エラー:-

 Class 'XTCPDF' not found   

しかし、Vendor フォルダに XTCPF というクラス名があります....何か助けてください ?? ありがとう

4

2 に答える 2

3

あなたは変更を試みます:

App::import('Vendor','xtcpdf');

App::import('Vendor','tcpdf/xtcpdf');

または、このチュートリアルに従ってください: http://www.pedroventura.com/cakephp/cear-archivos-pdf-con-cakephp/

まとめ:

ファイル: app/vendors/tcpdf/xtcpdf.php

<?php

    App::import('Vendor','tcpdf/tcpdf');

    class XTCPDF  extends TCPDF
    {

        var $xheadertext  = 'PDF creado using CakePHP y TCPDF';
        var $xheadercolor = array(0,0,200);
        var $xfootertext  = 'Copyright © %d XXXXXXXXXXX. All rights reserved.';
        var $xfooterfont  = PDF_FONT_NAME_MAIN ;
        var $xfooterfontsize = 8 ;

        function Header()
        {

            list($r, $b, $g) = $this->xheadercolor;
            $this->setY(10);
            $this->SetFillColor($r, $b, $g);
            $this->SetTextColor(0 , 0, 0);
            $this->Cell(0,20, '', 0,1,'C', 1);
            $this->Text(15,26,$this->xheadertext );
        }

        function Footer()
        {
            $year = date('Y');
            $footertext = sprintf($this->xfootertext, $year);
            $this->SetY(-20);
            $this->SetTextColor(0, 0, 0);
            $this->SetFont($this->xfooterfont,'',$this->xfooterfontsize);
            $this->Cell(0,8, $footertext,'T',1,'C');
        }
    }

?>

ファイル: app/views/layouts/pdf.ctp

<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>

コントローラーでのアクション:

function descargar($id = null)
{
    if (!$id)
    {
        $this->Session->setFlash('no has seleccionado ningun pdf.');
        $this->redirect(array('action'=>'index'));
    }
    Configure::write('debug',0);
    $resultado = $this->MiControlador->findById($id); // info from database
    $this->set("datos_pdf",$resultado);               // info to view (pdf)
    $this->layout = 'pdf';
    $this->render();
}

およびファイル: app/views/mi_aplicacion/descargar.ctp

<?php
App::import('Vendor','tcpdf/xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont = 'freesans';

$tcpdf->SetAuthor("");
$tcpdf->SetAutoPageBreak( false );
$tcpdf->setHeaderFont(array($textfont,'',10));
$tcpdf->xheadercolor = array(255,255,255);
$tcpdf->xheadertext = 'Fecha: '. date('d-m-Y',time());
$tcpdf->xfootertext = 'www.example.cl';

$tcpdf->AddPage();
$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'B',10);
$tcpdf->Cell(10,20,'Nombre:', 0, 0);

// more info

echo $tcpdf->Output('mi_archivo.pdf', 'D'); //D or I
?>
于 2013-10-27T03:17:00.983 に答える
1

http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-vendor-filesここでは、CakePHP 2.3.6 でベンダーをロードする方法を見つけることができます...

于 2013-06-19T13:36:20.743 に答える