Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework composer autoload

I have PHP project with the following vendors directory structure:

vendor
  zendframework
    zendframework
      library
       Zend
         ...
         ...
         Cache
         ...
         ...

When I put the following line into autoload_namespaces.php everything is ok:

'Zend\\Cache' => $vendorDir . '/zendframework/zendframework/library/',

but this line doesn't work:

'Zend\\Cache' => $vendorDir . '/zendframework/zendframework/library/Zend/Cache/',

The error is:

Fatal error: Class 'Zend\Cache\Storage\Adapter\MemcachedOptions' not found

What's wrong with my code? How can I load only Cache module from zend framework? Why does it work if I specify whole library folder?

like image 928
Phantom Avatar asked Dec 19 '13 11:12

Phantom


1 Answers

ZF1 classes have internal dependencies on other ZF classes. It's expecting the whole framework to be autoloaded. For every class not found error you get, you need to manually load that library too. Working through that list would be tedious, not impossible.

May I susggest an easier way forward:

Zend Framework 1.x can be installed with composer.

Add: "require": { "zendframework/zendframework1": "1.*" },

to your composer.json And do composer install from the command line. This will download zend framework and setup the library to autoload along with everything else composer is managing.

To get your zend framework app to use the composer autoloader you'll need to edit your applications index.php file and include the composer autoloader like so:

require_once realpath(APPLICATION_PATH . '/../vendor/autoload.php');
like image 198
txyoji Avatar answered Sep 23 '22 09:09

txyoji