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:
    1. Capitalize the first letter and all letters preceded by dashes.
    2. 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 /plib/library/ directory.

    For example, if a class is in /plib/library/website/Promo.php and the extension ID is my-site, the class name must be:

    Modules_MySite_Website_Promo.

Zend uses a similar approach for auto-loading classes. Read more about it here.

Limitations

The auto-loading of classes does not work in the /htdocs/public/ directory. If you need this feature, start the auto-loading manually by adding the following code to the beginning of a file:

require_once('sdk.php');
 

Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.