API15

JTable/getInstance

< API15:JTable

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

Returns a reference to the a Table object, always creating it

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

& getInstance($type, $prefix= 'JTable', $config=array())
Parameter Name Default Value Description
$type $type The table type to instantiate
$prefix $prefix A prefix for the table class name. Optional.
$config array() $options Configuration array for model. Optional.

Returns

database A database object

Defined in

libraries/joomla/database/table.php

Importing

jimport( 'joomla.database.table' );

Source Body

function &getInstance( $type, $prefix = 'JTable', $config = array() )
{
        $false = false;

        $type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
        $tableClass = $prefix.ucfirst($type);

        if (!class_exists( $tableClass ))
        {
                jimport('joomla.filesystem.path');
                if($path = JPath::find(JTable::addIncludePath(), strtolower($type).'.php'))
                {
                        require_once $path;

                        if (!class_exists( $tableClass ))
                        {
                                JError::raiseWarning( 0, 'Table class ' . $tableClass . ' not found in file.' );
                                return $false;
                        }
                }
                else
                {
                        JError::raiseWarning( 0, 'Table ' . $type . ' not supported. File not found.' );
                        return $false;
                }
        }

        //Make sure we are returning a DBO object
        if (array_key_exists('dbo', $config))  {
                $db =& $config['dbo'];
        } else {
                $db = & JFactory::getDBO();
        }

        $instance = new $tableClass($db);
        //$instance->setDBO($db);

        return $instance;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

Code Examples

getInstance example

 
$row =& JTable::getInstance('review', 'Table');
geomaras 00:35, 20 July 2010 (CDT) Edit comment
Advertisement