简体   繁体   中英

I have installed Zend Framework and need to set up include path in PHP?

I have dumped Zend Framework files in

"home/hotbuzz/public_html/include/zend/"

My hosting : 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"

But I want to use this home/hotbuzz/public_html/include/zend/

I had added these lined in my 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).

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)

set_include_path(dirname(__FILE__).PATH_SEPARATOR.get_include_path());

You were doing it right. You should call set_include_path in 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.

<?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:

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.

You may have more success if you use auto_prepend rather than include...

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?

您可以在bootstrap.php的第一行中附加以下代码:

set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/models/' . PATH_SEPARATOR . get_include_path());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM