0

i am working with phalcon php framework. I want to send data displayed in a div tag(it is a result of a search)to controller function, and controller will generate pdf file. But, pdf file is not generating. Here is my view:

       var imenica = "Ja se zovem Nedim Omerbegovic";
       $.ajax({
        url: '<?php echo  $this->url->get("test/creatingpdf");?>',
        type: 'POST',
        dataType: '',
        data: {imenica:imenica},
        success: function(data){
            alert(data);
            } ,
            error: function(){
                alert("Greska");
            }

    });


    });

and here is code for controller:

    public function creatingpdfAction(){
    $this->view->disable();
    $string =$_POST['imenica'];
    $this->view->setVars(array('ime'=>$string));

          $loader = new \Phalcon\Loader();
    $loader->registerClasses(
     array(
    "mpdf"=> "C:/wamp/www/phalcon1/mpdf/mpdf.php"
 )
 );


    $loader->register();
    //$string = "Ja se zovem Nedim Omerbegovic";
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');
    $cont = $this->view->getRender('test', 'creatingpdf');
    //generisanje pdf dokumenta
    $pdf = new mpdf();
    $pdf->WriteHTML($cont, 2);
    $br = rand(0,100000);
    $ispis = "Pobjeda Rudet-Izvjestaj-".$br;
    $pdf->Output($ispis, 'I');
  }

How can i see generated pdf file in this way of warking

4

1 回答 1

0

查看 TCPDF @ http://www.tcpdf.org/以获得绝对适用于 Phalcon 的 PDF 库。虽然这不是 Phalcon 特定的问题(因为 Phalcon 没有本机 PDF 库),但您当然可以将它与 Phalcon 集成。如果您想这样做,您可以将 TCPDF 库注册为 Phalcon 的服务,并将该库包含在自动加载器中,就像您使用任何其他服务一样。

例子:

$di->set('tcpdf', function() {
    $tcpdf = new TCPDF();

    return $tcpdf;
});

这将使您的图书馆可以通过

$this->tcpdf

在扩展核心 Phalcon 功能的对象中或

\Phalcon\DI::getDefault()->getTcpdf();

静态的。

于 2013-10-06T18:47:10.783 回答