Actions

API15

Difference between revisions of "JTable/getInstance"

From Joomla! Documentation

< API15:JTable
(New page: ===Description=== Returns a reference to the a Table object, always creating it <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JTable/getInstance|Ed...)
 
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JTable/getInstance|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JTable/getInstance}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 82: Line 82:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JTable/getInstance|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JTable/getInstance}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 97: Line 97:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 13:52, 12 May 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

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

<CodeExamplesForm />

getInstance example

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