API15:JTable/getInstance
From Joomla! Documentation
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
geomaras 00:35, 20 July 2010 (CDT) Edit comment
