Back to BaseDatabaseModel class

Method getTable

public \Joomla\CMS\Table\Table
getTable
(mixed $name = '', mixed $prefix = '', mixed $options = array())
Method to get a table object, load it if necessary.
Parameters
  • string $name The table name. Optional.
  • string $prefix The class prefix. Optional.
  • array $options Configuration array for model. Optional.
Returns
  • \Joomla\CMS\Table\Table A Table object
Since
  • 3.0
-
  • \Exception

Method getTable - Source code

/**
 * Method to get a table object, load it if necessary.
 *
 * @param   string  $name     The table name. Optional.
 * @param   string  $prefix   The class prefix. Optional.
 * @param   array   $options  Configuration array for model. Optional.
 *
 * @return  Table  A Table object
 *
 * @since   3.0
 * @throws  \Exception
 */
public function getTable($name = '', $prefix = '', $options = array())
{
    if (empty($name)) {
        $name = $this->getName();
    }
    // We need this ugly code to deal with non-namespaced MVC code
    if (empty($prefix) && $this->getMVCFactory() instanceof LegacyFactory) {
        $prefix = 'Table';
    }
    if ($table = $this->_createTable($name, $prefix, $options)) {
        return $table;
    }
    throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_TABLE_NAME_NOT_SUPPORTED', $name), 0);
}