【问题标题】:ZF2 and DOMPDF autoloading issueZF2 和 DOMPDF 自动加载问题
【发布时间】:2013-03-11 08:30:35
【问题描述】:

我在我的项目中使用来自here 的 Zend Loader,我无法为 DOMPDF 配置 Zend 自动加载器,与 dompdf 自动加载器并行工作。有什么方法可以设置 zend 自动加载以使其回退到 dompdf 自动加载器。

我看到了一些示例,例如使用 pushAutoLoader,但这似乎使用 Zend 旧版本(可能是 v

    require_once('dompdf/dompdf_config.inc.php' );
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->pushAutoloader('DOMPDF_autoload', '');

在 ZF2 Loader 中 pushAutoloader() 的替代方法是什么?我现在没有看到任何这样的方法。

还有一件事我不能使用'fallback_autoloader' => true, 选项,因为我使用的是 php 5.3.1,这给了我错误:

  `Call to undefined function Zend\Loader\stream_resolve_include_path()`

看来stream_resolve_include_path() 是在 php 5.3.2 中添加的

【问题讨论】:

    标签: php zend-framework2 dompdf zend-loader


    【解决方案1】:

    这似乎是一个小故障,刚刚发现 DOMPDF 配置文件正在使用一种过时的方式来注册其自动加载器,例如

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

    解决方法是使用spl_autoload_register bcz php spl_autoload_register vs __autoload? 并将上面的代码替换为一行,并对自动加载功能进行小幅更新

    function DOMPDF_autoload($class) { 
      //don't check for namespaced files/classes   
      if(strpos($class, "\\") > 0) return;
    
      if($class=='UFPDF') return ;
    
      $filename = mb_strtolower($class) . ".cls.php";
    
      require(DOMPDF_INC_DIR . "/$filename");
    }
    
    spl_autoload_register('DOMPDF_autoload');
    

    干杯:)

    【讨论】:

    • dompdf 不再使用此方法注册其自动加载器。在 0.6.0 中,自动加载功能得到了显着改进。 0.6.0 版本仍被标记为 beta,但它与之前的版本 (0.5.1) 一样稳定,我们强烈建议您试一试。 github.com/dompdf/dompdf
    猜你喜欢
    • 1970-01-01
    • 2014-08-20
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2011-08-17
    • 2014-08-02
    • 2018-07-11
    相关资源
    最近更新 更多