Joomla getTable() Method

Base Database Model
Joomla getTable() Method

It is a method to get a table object, load it if necessary.

  • string $name - The table name. Optional.
  • string $prefix - The class prefix. Optional.
  • array $options - Configuration array for model. Optional.
  • return \JTable - A \JTable object
public function getTable($name = '', $prefix = 'Table', $options = array())
{
if (empty($name))
{
$name = $this->getName();
}

if ($table = $this->_createTable($name, $prefix, $options))
{
return $table;
}

throw new \Exception(\JText::sprintf('JLIB_APPLICATION_ERROR_TABLE_NAME_NOT_SUPPORTED', $name), 0);
}

The method uses another protected method: _createTable()

_createTable Method

It is a method to load and return a model object.

  • string $name - The name of the view
  • string $prefix - The class prefix. Optional.
  • array $config - Configuration settings to pass to \JTable::getInstance
  • return \JTable|boolean - Table object or boolean false if failed
protected function _createTable($name, $prefix = 'Table', $config = array())
{
// Clean the model name
$name = preg_replace('/[^A-Z0-9_]/i', '', $name);
$prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);

// Make sure we are returning a DBO object
if (!array_key_exists('dbo', $config))
{
$config['dbo'] = $this->getDbo();
}

return \JTable::getInstance($name, $prefix, $config);
}

 

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive