0

What is the best way to autoload abstract classes

I have a class Formprocessor_Userregistrate extends Formprocessor Both files are in the same directory, but it cannot find Formprocessor

I already used $autoloader->registerNamespace('Formprocessor_');

When I change the name of Formprocessor into Formprocessor_Formprocessor; I get an "invalid controller" exception

What is the best technique to load those abstract classes?

thanks, Richard

Richard
  • 4,516
  • 11
  • 60
  • 87

1 Answers1

1

ZF convention specifies that you should keep your abstract at the same directory level as the concrete implementations. So, you probably want this:

Formprocessor/Userregistrate.php

Which would contain:

class Formprocessor_Userregistrate extends Formprocessor_Abstract

And this:

Formprocessor/Abstract.php

Which would contain

abstract class Formprocessor_Abstract
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • Do I have to add the keyword "abstract"??? Is that not the same as calling the abstract class FormProcessor_Formprocessor like I try'd already. – Richard Mar 23 '12 at 19:09
  • You don't *have* to, no. However, if you're following the ZF coding standard (which is generally a good idea when you're developing ZF applications,) then you should name all abstract classes like *_Abstract. – Alex Howansky Mar 23 '12 at 19:14
  • I know NOW that "invalid controller" comes from Smarty; some conflict issue. Thanks for your help! – Richard Mar 23 '12 at 19:26
  • Your conflict may be due to your shallow level namespaces -- typically, you'd want to prefix all your classes with a global namespace common to all the classes in your app. E.g., instead of Formprocessor_Abstract, you'd have Myapp_Formprocessor_Abstract. (Or whatever...) See http://framework.zend.com/manual/en/coding-standard.naming-conventions.html for more details. – Alex Howansky Mar 23 '12 at 19:41