在没有骨架的应用程序中包含ZEND框架2.3(Include ZEND framework 2.3 in application without skeleton)

编程入门 行业动态 更新时间:2024-10-28 02:26:20
在没有骨架的应用程序中包含ZEND框架2.3(Include ZEND framework 2.3 in application without skeleton)

网上有很多关于包含ZEND的内容,但我仍然不知道如何简单地使用它(没有骨架)(在这种情况下我只想使用Zend\Dom\Query )

我想要: 1)只需在单个应用程序中包含完整的ZEND 2.3库 要么 2)包括一个ZEND 2.3模块

我正在使用NGINX,但实际上我只想通过PHP包含它。 任何提示,提示和/或链接?

我所做的是:

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'); ...

错误是: Fatal error: Class 'Zend_Dom_Query' not found in /SOMEDIR/myfile.php on line 12

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

最满意答案

通过PHP包含它的一种简单方法是:

1.确保Zend目录位于php include_path 。 假设Zend目录在library文件夹中,你的index.php文件中会有这样的东西:

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

2.现在首先包含Zend/Loader/StandardAutoloader.php ,然后使用它来加载其他类。 你可以这样做 :

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

使用$autoloader->register() ,每次要调用类时都不需要包含文件。 你只需要实现你的课程:

$dom = new Zend\Dom\Query($html);

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);

更多推荐

本文发布于:2023-07-05 02:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1032104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:骨架   应用程序   框架   ZEND   framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!