如何在Controller中包含任何php

Agu*_*bat 4 php controller include symfony

我想在控制器内调用一个php文件,但它出现如下错误:

Fatal error: Class 'AppBundle\Controller\DOMPDF' not found in ....
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

require_once(__DIR__.'/../../../../dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream('report_'.$name.'.pdf');
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮助我?谢谢

Mat*_*teo 6

要在symfony2项目中使用DOMPDF PHP库,您可以使用DompdfBundle.按照github页面中的说明操作.

安装后,您可以将其用作服务,如文档中所述:

$dompdf = $this->get('slik_dompdf');

// Generate the pdf
$dompdf->getpdf($html);

// Either stream the pdf to the browser
$dompdf->stream('report_'.$name.'.pdf');
Run Code Online (Sandbox Code Playgroud)

希望这有帮助