Ajax调用中的Zend_Translate

时间:2015-12-13 11:46:17

标签: ajax zend-framework zend-translate

我目前正在使用Zend_Translate本地化项目。当尝试在ajax调用请求的php文件中使用适配器时,我收到以下错误消息:

Warning: require_once(Zend/Exception.php): failed to open stream:
File or Folder not found in
/my/include/path/Zend/Translate/Exception.php on
line 26

Fatal error: require_once(): Failed opening required
'Zend/Exception.php' (include_path='my/include/path') in
/my/include/path/Zend/Translate/Exception.php on
line 26

因此,它似乎是一个相对路径问题。我特别对'require_once(Zend / Exception.php)'错误感到困惑,因为在Zend主文件夹中没有这样的文件 - 但是,如前所述,非ajax调用工作正常。

我尝试使用if语句来检查文件的调用位置,并相应地调整include_path。这至少允许以下行在ajax和非ajax调用中工作。

require(get_include_path().'/Zend/Translate.php');

Zend_Loader::loadClass('Zend_Translate');

然而,上述错误仍然存​​在。

Zend是从包装类中加载的。这是路径结构:

class/                   class files, including a Zend wrapper class
js/                      js-files
js/ajax/                 php-files
vendor/Zend/...          Zend_Translate files

如果有更多信息有用,请告诉我。

1 个答案:

答案 0 :(得分:0)

在开始使用Zend Translate作为独立组件之前添加以下行

set_include_path(implode(PATH_SEPARATOR, array(
    realpath('path/to/zend/library'),
    get_include_path(),
)));

     require_once 'Zend/Loader/Autoloader.php';

        $autoloader = Zend_Loader_Autoloader::getInstance();

哪里

  

路径/到/ Zend的/文库

是Zend Framework 1库文件夹,其中存在Zend目录。