weixin_33704234 2015-12-13 11:46 采纳率: 0%
浏览 17

Zend_Translate在Ajax调用中

I'm currently in the process of localizing a project with Zend_Translate. When trying to use the adapter in a php-file requested by an ajax call, I get the following error message(s):

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

Thus, it seems to be a relative path problem. I'm particular confused about the 'require_once(Zend/Exception.php)' error since in the Zend main folder there is no such file -- however, as said before, non-ajax calls work just fine.

I tried to use if-statements to check from where the file's calling and adjust the include_path accordingly. This at least allowed the following lines to work both in ajax and non-ajax calls.

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

Zend_Loader::loadClass('Zend_Translate');

However the above mentioned errors persist.

Zend is loaded from within a wrapper class. Here's the path structure:

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

Let me know if more information is helpful.

  • 写回答

1条回答 默认 最新

  • weixin_33722405 2015-12-14 05:33
    关注

    Add the following lines before starting to use Zend Translate as an independent component

    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();
    

    Where

    path/to/zend/library

    is Zend Framework 1 library folder inside which Zend directory is present.

    评论

报告相同问题?