Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

PhalconPHP and DOMPDF

Good afternoon, trying to include this library for use in DOMPDF Phalcon views. I've checked the directory where the library, but can not find the class. Can anyone help me solve this? Thanks in Advance you very much. This did this / public / index.php

$ config = new Phalcon\Config\Adapter\Ini(__DIR__ .  '/app/config/config.ini'); 

/ / Register an autoloader 
     $ loader = new \ Phalcon \ Loader (); 
     $ loader-> registerDirs (
         array (
             __DIR__. $ config-> application-> controllersDir, 
             __DIR__. $ config-> application-> pluginsDir, 
             __DIR__. $ config-> application-> libraryDir, 
             __DIR__. $ config-> application-> modelsDir, 
             __DIR__. $ config-> application-> libraryDir. "pdf /", / / ​​Add the folder for the PDF Dom 
             __DIR__. $ config-> application-> libraryDir. "pdf / include /" 
             __DIR__. $ config-> application-> libraryDir. "pdf / lib /" 
         ) 
     ) -> register ();

please format source code with this guide http://forum.phalconphp.com/help



27.9k
Accepted
answer

Hi, check if path for your library is ok and try http://localhost/pdf/render

class PdfController extends \Phalcon\Mvc\Controller
{
    public function renderAction()
    {
        $this->view->disable();

        require_once("app/library/pdf/dompdf_config.inc.php"); //you have to download this library and locate this file to bootstrap dompdf

        $html =
            '<html><body>'.
            '<p>test</p>'.
            '</body></html>';

        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream("sample.pdf");
    }
}
edited Jul '14

I am using phalcon 1.3.2 but it not work

class IndexController extends ControllerBase {

public function indexAction()
{
    $this->view->disable();
    require_once "app/library/dompdf/dompdf_config.inc.php";
    $html =
        '<html><body>'.
        '<p>test</p>'.
        '</body></html>';

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("sample.pdf");
}

}

I add pdfDir in config/config.php like

return new \Phalcon\Config(array( 'database' => array( 'adapter' => 'Mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'test', ), 'application' => array( 'controllersDir' => DIR . '/../../app/controllers/', 'modelsDir' => DIR . '/../../app/models/', 'viewsDir' => DIR . '/../../app/views/', 'pluginsDir' => DIR . '/../../app/plugins/', 'pdfDir' => DIR . '/../../app/library/', 'cacheDir' => DIR . '/../../app/cache/', 'baseUri' => '/blog/'

)

));

and in config/loader.php

$loader->registerDirs( array( $config->application->controllersDir, $config->application->modelsDir, $config->application->pdfDir

)

)->register();

and pdf not showing, after that i tried to remove this syntax (config/loader.php)

after I return again to the initial conditions but still error:

IndexController handler class cannot be loaded Why?