Welcome Guest, Not a member yet? Register   Sign In
[FIXED] __autoload issue when using DOMpdf
#1

[eluser]Ñuño Martínez[/eluser]
Hello.

I'm trying to create a document with DOMpdf but I have a problem with the __autoload stuff. DOMpdf tryes to autoload file "ci_db.cls.php", which obviously doesn't exists because it auto-builds the filename from CodeIgniter's CI_DB class. I've deleted the __autoload stuff from dompdf_config.inc.php file but then PHP says it can't find the DOMPDF class.

How can I avoid to autoload any "autoloadable CodeIgniter's class"?
#2

[eluser]Dam1an[/eluser]
Can you not just manually include the files needed by domPDF?
#3

[eluser]Ñuño Martínez[/eluser]
It's a solution but seems like DOMpdf uses __autoload to load all the files, and there are some of them. Sad

Does somebody know a workaround?
#4

[eluser]Dam1an[/eluser]
Quote:How can I avoid to autoload any “autoloadable CodeIgniter’s class”?
Are you afraid of CI trying to use __autoload, and it failing to find the correct files?

If I remember correctly, __autoload shouldn't be called for CI stuff, assuming you've loaded it yourself
Alternativly, if all domPDF have a common prefix/suffix, just search for this in __autoload
#5

[eluser]Ñuño Martínez[/eluser]
Actually I'm not using __autoload. Actually I have no idea how does it works. I have no idea where it's used. I only know it's a "magic" funcion because it has the "__" prefix and because GVim highlights it as a keyword.

DOMpdf defines an __autoload function if it doesn't exists, this way:
Code:
/**
* DOMPDF autoload function
*
* If you have an existing autoload function, add a call to this function
* from your existing __autoload() implementation.
*
* @param string $class
*/
function DOMPDF_autoload($class) {
  $filename = mb_strtolower($class) . ".cls.php";
  require_once(DOMPDF_INC_DIR . "/$filename");
}

if ( !function_exists("__autoload") ) {
  /**
   * Default __autoload() function
   *
   * @param string $class
   */
  function __autoload($class) {
    DOMPDF_autoload($class);
  }
}

Then "somewhere" it calls "__autoload ('CI_DB');". AFAIK 'CI_DB' is a CodeIgniter's class, but since __autoload is defined by DOMpdf it tryes to load "ci_db.class.pdf" at the DOMpdf's directory.

If I delete the __autoload definition then it doesn't loads any of the DOMpdf's files. There are a lot (I've added 18 "require_once" on my source and it still saying I need more...) so it's not a good solution.

I want to know how to prevent that.
#6

[eluser]TheFuzzy0ne[/eluser]
Please add the closing [/code] tag to your post above, as it's breaking the forum.
#7

[eluser]Dam1an[/eluser]
Do you use CI autoloading to load the database library? Maybe domPDF is trying to __autoload before CI manages to load it
#8

[eluser]Ñuño Martínez[/eluser]
[quote author="Dam1an" date="1241018643"]Do you use CI autoloading to load the database library? Maybe domPDF is trying to __autoload before CI manages to load it[/quote]

No, I don't. Actually I'm using ADODB because I find it more comfortable.

BTW I did look at CI's autoload.php file and all arrays are empty. And as I've said I never used __autoload in my life.

I'm getting ill with this.
#9

[eluser]Ñuño Martínez[/eluser]
I've fixed it. It was so easy I feel as stupid because I didn't think that before.

Just modify function DOMPDF_autoload at dompdf_config.inc.php:
Code:
function DOMPDF_autoload($class) {
# Do not autoload CodeIgniter classes.
  if (strpos ($class, 'CI_') === false) {
    $filename = mb_strtolower($class) . ".cls.php";
    require_once(DOMPDF_INC_DIR . "/$filename");
  }
}

Of course that would introduce new problems if using __autoload to load CI's classes but that is other problem. :p
#10

[eluser]wiredesignz[/eluser]
Code:
/* don't autoload CI_ or subclass prefixed classes */
    if (strstr($class, 'CI_') OR strstr($class, config_item('subclass_prefix'))) return;




Theme © iAndrew 2016 - Forum software by © MyBB