3

I just upgraded from ZF 1.7 to ZF 1.9, and almost everything works fine... except for Autoloader.

Old:

require_once('Zend/Loader.php');  
Zend_Loader::registerAutoload();

New:

require_once 'Zend/Loader/Autoloader.php';  
$loader = Zend_Loader_Autoloader::getInstance();  
$loader->registerNamespace('MySiteName_');
$loader->setFallbackAutoloader(true);

The files I need to auto-load are mostly not namespaced (because it's a large project from pre-namespacing). They are in the following directories:

  • /application/controllers
  • /common/models
  • /library
  • /vendor

The site seems to work fine EXCEPT that it can't find /library/Form.php
It used to be able to, but not anymore. It works if I add a require_once 'library/Form.php', but that shouldn't be necessary, and I'm worried that if I start doing that in some places, I'll need to abandon the autoloader and hard-code all includes. I thought adding "setFallbackAutoloader(true)", combined with having "library" in my include path would fix it, but it didn't.

My include path is:
.:/Users/lofye/Documents/htdocs/mysitename/vendor
:/Users/lofye/Documents/htdocs/mysitename/common
:/Users/lofye/Documents/htdocs/mysitename/common/models
:/Users/lofye/Documents/htdocs/mysitename/library
:/Users/lofye/Documents/htdocs/mysitename

Any help greatly appreciated!

lo_fye
  • 6,790
  • 4
  • 33
  • 49

3 Answers3

1

Your autoloader is only going to attempt loading classes that begin with MySiteName_. Try adding Form as a namespace maybe?

$loader->registerNamespace('Form');
gnarf
  • 105,192
  • 25
  • 127
  • 161
  • The problem isn't just Form. It's Form and the other 50 un-namespaced classes I have in the same directory. I only mention Form to keep the question simple. – lo_fye Dec 12 '09 at 11:59
  • You could try registering an empty namespace? – gnarf Dec 12 '09 at 19:30
0

You said it works if you do this:

require_once 'library/Form.php';

But, if your library path is included, then you should be specifying, as autoloader does, like this:

require_once 'Form.php';

Try typing require_once 'Form.php'; into your script. Does it bomb? Then, your include path doesn't have /library, and that would need to be fixed.

Derek Illchuk
  • 5,638
  • 1
  • 29
  • 29
  • I just tried require_once 'Form.php' and you're right, it bombs. Odd, because I have not changed the include path, and it was working fine before upgrading Zend Framework :-| – lo_fye Dec 09 '09 at 17:19
0

The class name inside the file library/Form.php should be Form. What's your class name?

I tested here and is working fine.

Luiz Damim
  • 3,803
  • 2
  • 27
  • 31