jimport function (this is now discourage in favor of using JLoader::register). Only class names that begin with upper case "J" will be considered for auto-loading. Following the "J" prefix, the class name must be in camel case and each segment of the name will represent a folder path below JPLATFORM_PATH/joomla where the last segment of the name is the name of the class file. If there is only one part to the class name, the auto-loader will look for the file in a folder of the same name. Folder names must be in lower case.
JDatabase should be located in JPATH_PLATFORM/joomla/database/database.php
JDatabaseQuery should be located in JPATH_PLATFORM/joomla/database/query.php
JDatabaseQueryMysql should be located in JPATH_PLATFORM/joomla/database/query/mysql.php
JClassname located in JPATH_PLATFORM/joomla/classname/classname.php, or |
JPathtoClassname located in JPATH_PLATFORM/joomla/pathto/classname.php |
JLoader's register and discover methods.
register method. This method takes the class name, the path to the class file, and an option boolean to force an update of the class register.
// Register an adhoc class.
JLoader::register('AdhocClass', '/the/path/adhoc.php');
// Register a custom class to override as core class.
// This must be done before the core class is loaded.
JLoader::register('JDatabase', '/custom/path/database_driver.php', true);/libraries/joomla folder). This allows for several scenarios:
| A developer can register the prefix of custom classes, and a root path to allow the auto-loader to find them. |
| A developer can register an extra path for an existing prefix (for example, this allows the Joomla CMS to have custom libraries but still using the "J" prefix). |
| A developer can register a force override for a prefix. This could be used to completely override the core classes with a custom replacement. |
// Tell the auto-loader to also look in the /libraries/cms folder for "J" prefixed classes.
JLoader::registerPrefix('J', JPATH_PLATFORM . '/cms');
// Tell the auto-loader to look for classes starting with "Foo" in a specific folder.
JLoader::registerPrefix('Foo', '/path/to/custom/packages');
// Tell the auto-loader to reset the "J" prefix and point it to a custom fork of the platform.
JLoader::registerPrefix('J', '/my/platform/fork', true);JLoader's discover method. The discover method looks at the file names in a folder and registers classes based on those names. Additional arguments can be used to update the class register and recurse into sub-folders.
// Register all files in the /the/path/ folder as classes with a name like:
// Prefix<Filename>
JLoader::discover('Prefix', '/the/path/');