Class Naming Conventions
The system allows to call your classes from almost all places of your code without preliminary requiring them. For this, you should properly name the classes and put the file which contains the class into a particular directory. Another goal of such conventions is to avoid conflicts between classes of different extensions. Also, for some situations you are required to adhere to the naming conventions to satisfy the requirements of hooks. For example, if you wish to add a dashboard widget, you are required to follow the conventions because the system needs to automatically discover and load this class.
The naming conventions are as follows:
The class name must start with the Modules_ExtensionName prefix. Here ExtensionName is the ID of your extension changed as follows:
- Capitalize the first letter and all letters preceded by dashes.
- Remove all dashes.
Example: if your extension ID is “my-site”, the class name must start with “Modules_MySite”.
The class name must include the path to the directory where the file containing the class resides. The slashes (/) in the path are substituted by underscores (_). The path must be given relatively to the extension’s
For example, if a class is in
/plib/library/website/Promo.phpand the extension ID is my-site, the class name must be:
Zend uses a similar approach for auto-loading classes. Read more about it here.
The auto-loading of classes does not work in the
directory. If you need this feature, start the auto-loading manually by
adding the following code to the beginning of a file: