我试图在Lion上设置Zend框架,我在
中安装了"Zend"/usr/local/zend/share/ZendFramework/library/Zend
我的PHP路径是(php -i | grep include_path
):
include_path => .: => .:
I tried to do:
<?php
set_include_path('ZendFramework-1.10.3-minimal/library/'.get_include_path());
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
?>
我在浏览器中看到的是:
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in /Users/ngoles/Programming/WWW/ApparelDream/appareldream/test.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='ZendFramework-1.10.3-minimal/library/.:') in /Users/ngoles/Programming/WWW/ApparelDream/appareldream/test.php on line 3
正确设置路径的建议
答案是我在这里看到的评论和答案的组合。下面是来自Zend的一个简单示例。
// the first two lines should set it up for the Zend library
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
// these are for custom libraries, two different ways of doing it
// and NOT necessary if you don't have any custom libraries
$loader->registerNamespace('Foo_');
$loader->registerNamespace(array('Foo_', 'Bar_'));
Zend是这么说的:
默认情况下,这将允许加载带有"Zend_"类命名空间前缀的任何类。或者"ZendX_",只要它们在你的include_path上。
如果您希望使用其他名称空间前缀会发生什么?最好、最简单的方法是在实例上调用registerNamespace()方法。您可以传递一个名称空间前缀,或者一个名称空间前缀数组:
然后,当然,确保在使用set_include_path()
分配多个路径时包括PATH_SEPARATOR
,否则它将只是连接它们。
我在index.php文件中是这样做的。
set_include_path(
'/usr/local/zend/share/ZendFramework/library' .
PATH_SEPARATOR . get_include_path() .
PATH_SEPARATOR . '.'
);