How To Correctly Import From Component?

Hello,

If I am importing a class from a controller action, it works fine:




Yii::import('vendor.*');

require_once('mikehaertl/phpwkhtmltopdf/src/Pdf.php');

$pdf = new Pdf(  $action );



but when I use this code in my component (/components/Printer.php), I see this warning:




include(Pdf.php): failed to open stream: No such file or directory



How can be imported/required the Pdf class from my Printer component?

Thank you!

Try something like:


require_once \dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DirName' . DIRECTORY_SEPARATOR . 'FileName.php';

where dirname(FILE) is your starting directory so you can get the proper relative path.

Thank you!

That was my mistake, I forgot to add the ‘use mikehaertl\wkhtmlto\Pdf’ line.