我已经安装了 Zend Framework 并且需要在 PHP 中设置包含路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/452848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I have installed Zend Framework and need to set up include path in PHP?
提问by Pouya Fani
I have dumped Zend Framework files in
我已将 Zend 框架文件转储到
"home/hotbuzz/public_html/include/zend/"
“家/hotbuzz/public_html/include/zend/”
My hosting : linux
我的主机:linux
I want to load it in my script. Whenever I load I get this error.
我想在我的脚本中加载它。每当我加载时,我都会收到此错误。
Some info: I asked about my Zend, to hosting guys they said its located in "usr/local/zend"
一些信息:我询问了我的 Zend,托管人他们说它位于“usr/local/zend”
But I want to use this home/hotbuzz/public_html/include/zend/
但我想用这个 home/hotbuzz/public_html/include/zend/
I had added these lined in my PHP:
我在我的 PHP 中添加了这些内衬:
set_include_path(dirname(__FILE__).';'.get_include_path());
require_once 'Zend/Loader.php';
I get this error
我收到这个错误
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Exception.php' (include_path='/home/hotbuzz/public_html/include;.:/usr/lib/php:/usr/local/lib/php') in /home/hotbuzz/public_html/include/Zend/Loader.php on line 87
I want to set include path in my PHP code and configure it (.htaccess).
我想在我的 PHP 代码中设置包含路径并配置它 (.htaccess)。
回答by stunti
As I said in your previous question. Do not use ';' but use PATH_SEPARATOR. This is a PHP constant that represent the right separator for your system (semi-colon on windows and colon on linux)
正如我在您之前的问题中所说。不使用 ';' 但使用 PATH_SEPARATOR。这是一个 PHP 常量,代表您系统的正确分隔符(Windows 上的分号和 linux 上的冒号)
set_include_path(dirname(__FILE__).PATH_SEPARATOR.get_include_path());
回答by farzad
You were doing it right. You should call set_include_pathin first lines of your main script (index.php) and then include/require zend framework files. Remember to rename your Zend Framework containing folder to 'Zend' (uppercase Z) to follow ZF naming conversions, then put your Zend folder in your include directory.
你做得对。您应该调用set_include_path主脚本 (index.php) 的第一行,然后包含/需要 zend 框架文件。请记住将包含 Zend Framework 的文件夹重命名为“Zend”(大写 Z)以遵循 ZF 命名转换,然后将您的 Zend 文件夹放在您的包含目录中。
<?php
$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = 'include';
$newIncludePath[] = get_include_path();
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);
// now include path is setup and we can use zend
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoLoad('Zend_Loader', true);
// the rest of the code
?>
If you put your Zend directory in your include path, and not the include directory (that contains the Zend directory), you may not use this:
如果您将 Zend 目录放在包含路径中,而不是包含目录(包含 Zend 目录),则不能使用以下命令:
require_once 'Zend/Loader';
instead you should use:
相反,您应该使用:
require_once 'Loader';
which is not a good idea. by using the Zend/* model, you will remember which files are included from Zend Framework and which files are you own. so just add the include directory to your include path.
这不是一个好主意。通过使用 Zend/* 模型,您将记住 Zend Framework 包含哪些文件以及您拥有哪些文件。所以只需将包含目录添加到您的包含路径中。
回答by Uresu
You may have more success if you use auto_prepend rather than include...
如果您使用 auto_prepend 而不是包含,您可能会取得更大的成功...
php_value include_path /home/hotbuzz/public_html/include/zend/
php_value auto_prepend_file Zend/Loader.php
What do you get in the apache log on startup and execution with that?
你在启动和执行的 apache 日志中得到了什么?
回答by Pouya Fani
you can attach the below code in the first line of your bootstrap.php:
您可以在 bootstrap.php 的第一行附加以下代码:
set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/models/' . PATH_SEPARATOR . get_include_path());

