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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化