Zend framework 如何更改Zend Framework的include目录

Zend framework 如何更改Zend Framework的include目录,zend-framework,Zend Framework,我收到以下错误消息: Warning: include_once(Zend\Db.php) [function.include-once]: failed to open stream: No such file or directory in C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83 Warning: include_once() [function.include]: Failed opening 'Ze

我收到以下错误消息:

Warning: include_once(Zend\Db.php) [function.include-once]: 
failed to open stream: No such file or directory in 
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83    

Warning: include_once() [function.include]: 
Failed opening 'Zend\Db.php' for inclusion (include_path='VPZ/') in 
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83

Warning: require_once(Zend/Exception.php) 
[function.require-once]: failed to open stream: 
No such file or directory in 
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87

Fatal error: require_once() [function.require]: 
Failed opening required 'Zend/Exception.php' (include_path='VPZ/') in 
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87

我想包括ZendXXX\Db.php

如何更改它

使用
设置包含路径()

例如:

 set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');

我通常将框架文件存储在“库”文件夹下:

  • 应用
  • 公共网页
  • 图书馆
    • 泽德
    • 普通的
    • 等等
然后在我的引导文件或前端控制器中,我将“library”文件夹添加到包含路径:

set_include_path(get_include_path() . PATH_SEPARATOR . '../library');
另见:

创建一个目录(比如“lib”),并将Zend目录放在其中。因此,您的目录结构如下所示:

- application
- lib
  |- Zend
- wwwroot
  |- index.php
include 'Zend/Loader.php';
require_once 'Zend/Db.php';
现在,您应该将lib添加到include路径中。编辑index.php文件:

$includePath = array();
$includePath[] = '.';
$includePath[] = './../application';
$includePath[] = './../lib';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
现在在include路径中有了lib。您可以包括所有Zend组件,如下所示:

- application
- lib
  |- Zend
- wwwroot
  |- index.php
include 'Zend/Loader.php';
require_once 'Zend/Db.php';
最好的方法是先包含Zend_Loader,然后使用它来加载类。这样做:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Db');
您还可以注册到自动加载类。只需将这一行添加到您的代码中即可:

Zend_Loader::registerAutoLoad('Zend_Loader',true);
现在您不需要包含调用类的文件。只需实例化您的类:

$session=new Zend_session_名称空间(“用户”)


没有必要包含“Zend/Session/Namespace.php”。

其他建议之所以提到这样做,是因为这是一个糟糕的举动——换句话说,你做得不对

您可以创建一个子目录并将其命名为Zendxxx,但随后必须将其添加到include_路径中,并在每次发布新命名版本时对其进行更改


我冒昧地猜测一下,你没有一个好的方法来测试网站(所以你想把它锁定到ZF的一个特定版本),而且,你没有使用版本控制,所以你想让站点目录中的所有以前版本的代码都能够返回,如果直接在服务器上更改实时运行代码时发现问题。

无库项目,从一个位置包括库
项目C:\xampp\htdocs\my\application
库C:\xampp\Zend\library

在index.php中进行更改

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR,  
           array(realpath(APPLICATION_PATH.'/../../../Zend/library'),get_include_path(),)));

这将违反Zend类和文件命名约定。。。这就是路!如果使用autoload,则只需包含加载程序,然后就可以调用整个框架中的每个类和函数,而不包含任何内容。