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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题