duandongji2231 2012-10-16 15:47
浏览 33
已采纳

Zend PDF和Zend Guard Loader入门

I'm trying to install Zend PDF in order to fill out editable PDFs on my client's shared hosting account (media temple). I have it enabled now, confirmed in phpinfo http://i.imgur.com/lDiLk.png but after that, I can't find out what I need to get started. If I try loading the Zend_Pdf class, I receive a "Fatal error: Class 'Zend_Loader' not found" message.

  • 写回答

2条回答 默认 最新

  • duandi8613 2012-10-16 15:50
    关注

    These are very different. Zend Guard Loader is used to run PHP scripts encoded by Zend Guard. And Zend Loader component is used, among other things, to simplify the development. For example, this...

    $pdf = new Zend_Pdf(); // what's Zend_Pdf, people?
    

    ... statement is meaningless to PHP unless it knows what is Zend_Pdf class. Thankfully, in PHP there's a special mechanism of importing these files automatically - autoloading. Here's how to do it with Zend_Loader:

    set_include_path(
        implode(PATH_SEPARATOR, array(
            get_include_path(),
            PATH_TO_ZF_LIBRARY
        )));
    
    require_once 'Zend/Loader/Autoloader.php';
    $autoloader = Zend_Loader_Autoloader::getInstance();
    ...
    $pdf = new Zend_Pdf(); // no error, as correct file should be imported automatically
    

    Actually, if it's only a single file that will use Zend component, it's not required that you use the autoloading mechanism. A simple require_once (no pun intended) would suffice:

    require_once 'Zend\Pdf.php';
    ...
    $pdf = new Zend_Pdf(); // oh, now I know all about Zend_Pdf!
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效