dp709369831 2014-08-17 09:09
浏览 34
已采纳

在没有骨架的应用程序中包含ZEND框架2.3

There is a lot on the web about including ZEND, but I still don't get how to simply use it (without a skeleton) (In this case I only want to use Zend\Dom\Query)

I would like to:
1) Simply include the complete ZEND 2.3 library in a single application
or
2) Include a single ZEND 2.3 module

I'm using NGINX, but actually I just want to include it via PHP. Any hints, tips and or links?

What I did was:

include('./library/Zend/Dom/Query.php');
$c = curl_init($u);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($c);  
$dom = new Zend\Dom\Query($html);
$results = $dom->execute('.foo .bar a');
...

Error is: Fatal error: Class 'Zend_Dom_Query' not found in /SOMEDIR/myfile.php on line 12

  • 写回答

2条回答 默认 最新

  • dtng5978 2014-08-17 10:22
    关注

    A simple way to include it via PHP is :

    1. Make sure that the Zend directory is on your php include_path. Assuming Zend directory is in the library folder you'll have something like this in your index.php file:

    $path= array();
    $path[] = '.';
    $path[] = './../library';
    $path[] = get_include_path();
    $path= implode(PATH_SEPARATOR,$path);
    set_include_path($path);
    

    2. Now just include Zend/Loader/StandardAutoloader.php first and then use it to load other classes. You can do this :

    require_once 'Zend/Loader/StandardAutoloader.php';
    $autoloader = new Zend\Loader\StandardAutoloader(array(
    'fallback_autoloader' => true,
     ));
    $autoloader->register();
    

    With the $autoloader->register(), you don't need to include files each time you want to call classes. You have just to instanciate your classes :

    $dom = new Zend\Dom\Query($html);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?