views:

470

answers:

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!

A: 

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
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
A: 

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
The class name is "Form". class Form extends Zend_Form
lo_fye
+1  A: 

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

$loader->registerNamespace('Form');
gnarf
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
You could try registering an empty namespace?
gnarf