Joomla 3.4 PHP basic:About JTable::getInstance in libraries/Joomla/table/table.PHP文件

Joomla 3.4 PHP basic:About JTable::getInstance in libraries/Joomla/table/table.PHP文件,php,joomla,Php,Joomla,当我遇到这个函数时,我正试图阅读和理解一些joomla核心PHP代码。它位于libraries/joomla/table/table.php第268行。在第305行函数的末尾,它返回一个由$tableClass创建的对象,我不明白的是,这个$tableClass类定义在哪里?以下是该功能的完整列表: public static function getInstance($type, $prefix = 'JTable', $config = array()) { // Sanitize

当我遇到这个函数时,我正试图阅读和理解一些joomla核心PHP代码。它位于
libraries/joomla/table/table.php
第268行。在第305行函数的末尾,它返回一个由
$tableClass
创建的对象,我不明白的是,这个
$tableClass
类定义在哪里?以下是该功能的完整列表:

public static function getInstance($type, $prefix = 'JTable', $config = array())
{
    // Sanitize and prepare the table class name.
    $type       = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
    $tableClass = $prefix . ucfirst($type);

    // Only try to load the class if it doesn't already exist.
    if (!class_exists($tableClass))
    {
        // Search for the class file in the JTable include paths.
        jimport('joomla.filesystem.path');

        $paths = self::addIncludePath();
        $pathIndex = 0;

        while (!class_exists($tableClass) && $pathIndex < count($paths))
        {
            if ($tryThis = JPath::find($paths[$pathIndex++], strtolower($type) . '.php'))
            {
                // Import the class file.
                include_once $tryThis;
            }
        }

        if (!class_exists($tableClass))
        {
            // If we were unable to find the class file in the JTable include paths, raise a warning and return false.
            JLog::add(JText::sprintf('JLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND', $type), JLog::WARNING, 'jerror');

            return false;
        }
    }

    // If a database object was passed in the configuration array use it, otherwise get the global one from JFactory.
    $db = isset($config['dbo']) ? $config['dbo'] : JFactory::getDbo();

    // Instantiate a new table class and return it.
    return new $tableClass($db);
}
公共静态函数getInstance($type,$prefix='JTable',$config=array())
{
//清理并准备表类名称。
$type=preg_replace('/[^A-Z0-9.-]/i',''$type);
$tableClass=$prefix.ucfirst($type);
//仅当类不存在时才尝试加载该类。
如果(!class_存在($tableClass))
{
//在JTable include path中搜索类文件。
jimport('joomla.filesystem.path');
$path=self::addIncludePath();
$pathIndex=0;
而(!class_存在($tableClass)&&$pathIndex
您可以在任何组件的管理部分的tables子文件夹中找到JTable类。每个文件都包含从JTable类扩展而来的表类。您不必重写此方法getInstance。 事实上,JTable可以非常简单。例如:

class XXXTableCity extends JTable
{
    /**
    * Constructor
    *
    * @param object Database connector object
    */
    function __construct( &$db ) {
        parent::__construct('#__xxx_cities', 'id', $db);
    }
}