Quick search:


include a class

The framework supplies special functions for including classes. It is important not to use php's include, include_once, require and require_once functions directly because of class name registration and requesthandler class loading override.

In general, to include a class, use the includeClass function. This function will include each class only once and register its class name so that the framework can retrieve the class name in correct case from an object. The first parameter this function takes is the class name. The class should be in the file with the same name as the class name, but prefixed with 'class' and extended with '.php'. The second parameter is the class location. It is a file path (with forward slashes) relative to the classes folder. Thus includeClass('MyClass', 'myFolder') will include 'classes/myFolder/classMyClass.php' (relative to the phpPeanuts root folder. As all application script run in their application folder, which must be a direct subfolder of the phpPeanuts root folder, they it will in fact be included using '../classes/myFolder/classMyClass.php').

If you do not know if a class file exists, you may try to include it using the 'tryIncludeClass' function. This function takes the same parameters as includeClass, but it will not trigger a warning if the class file is not found. It will return true if the class is included or was already included before, or false if the class file was not found or already not found before. 

All the above functions will not find class files that where generated after the first attempt to include it. If you generate classes dynamically, you should take a look at these functions in 'generalFunctions.php' in the pnt classfolder to see how you can  load and register a generated class file.