2

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.

DanceMichi
  • 31
  • 4

1 Answers1

0

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.

Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • Thanks for your idea. But it doesn't help. Note I'm only using the Zend_Translate adapter, not full ZF. When removing the require_once statement it results in a fatal error: **Class 'Zend_Exception' not found in /my/include/path/Zend/Translate/Exception.php on line 36**; not surprising since this line defines a class extending Zend_Exception. Removing this class as well results in Fatal Errors in the Gettext Adapter. Again, only for ajax calls. – DanceMichi Dec 14 '15 at 11:57
  • @DanceMichi Hi I have updated my answer kindly check now. – Mr Coder Dec 15 '15 at 07:33
  • Finally got it working. Problem was that Exception.php in Zend main folder was indeed missing. Apparently it didn't come with the zip I downloaded. When then adding relative paths for ajax calls via set_include_path everything now seems to work smoothly. No idea though why this problem only occurred with ajax calls. Thanks, nevertheless! – DanceMichi Dec 18 '15 at 12:26