Yii Framework Forum: How To Correctly Import From Component? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Correctly Import From Component? Rate Topic: -----

#1 User is offline   heal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 08-December 10
  • Location:Slovakia

Posted 11 September 2014 - 05:00 AM

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!
0

#2 User is offline   Bizley 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 317
  • Joined: 29-July 14
  • Location:Wrocław

Posted 11 September 2014 - 05:11 AM

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.
0

#3 User is offline   heal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 08-December 10
  • Location:Slovakia

Posted 11 September 2014 - 05:19 AM

Thank you!
That was my mistake, I forgot to add the 'use mikehaertl\wkhtmlto\Pdf' line.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users