如何更改 Zend Framework 的包含目录 [英] How to change include directory of 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 '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
i want to include ZendXXX\Db.php
如何改变它
推荐答案
创建一个目录(比如lib"),并将您的 Zend 目录放入其中.所以你的目录结构是这样的:
create a directory (say 'lib'), and put your Zend directory in it. so your directory structure looks like this:
- application
- lib
|- Zend
- wwwroot
|- index.php
现在您应该将 lib 添加到您的包含路径中.编辑您的 index.php 文件:
now you should add lib to your include path. edit your index.php file:
$includePath = array();
$includePath[] = '.';
$includePath[] = './../application';
$includePath[] = './../lib';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
现在您的包含路径中有您的库.您可以像这样包含所有 Zend 组件:
now you have your lib in your include path. you can include all Zend components like this:
include 'Zend/Loader.php';
require_once 'Zend/Db.php';
最好的方法是先包含 Zend_Loader,然后再用它来加载类.这样做:
the best way is too include Zend_Loader first and then use it to load classes. do this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Db');
您还可以注册自动加载类.只需将此行添加到您的代码之前:
you can also register to autoload classes. just add this line to your code after all those before:
Zend_Loader::registerAutoLoad('Zend_Loader',true);
现在您不需要包含文件来调用类.只需实例化您的课程:
now you do not need to include files to call classes. just instanciate your classes:
$session = new Zend_Session_Namespace('user');
$session = new Zend_Session_Namespace('user');
不需要包含Zend/Session/Namespace.php".
there is no need to include 'Zend/Session/Namespace.php'.
这篇关于如何更改 Zend Framework 的包含目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!