Back to Table class

Method getKeyName

public mixed
getKeyName
(mixed $multiple = false)
Method to get the primary key field name for the table.
Parameters
  • bool $multiple True to return all primary keys (as an array) or false to return just the first one (as a string).
Returns
  • mixed Array of primary key field names or string containing the first primary key field.
Since
  • 1.7.0
Class: Table
Project: Joomla

Method getKeyName - Source code

/**
 * Method to get the primary key field name for the table.
 *
 * @param   boolean  $multiple  True to return all primary keys (as an array) or false to return just the first one (as a string).
 *
 * @return  mixed  Array of primary key field names or string containing the first primary key field.
 *
 * @since   1.7.0
 */
public function getKeyName($multiple = false)
{
    // Count the number of keys
    if (\count($this->_tbl_keys)) {
        if ($multiple) {
            // If we want multiple keys, return the raw array.
            return $this->_tbl_keys;
        } else {
            // If we want the standard method, just return the first key.
            return $this->_tbl_keys[0];
        }
    }
    return '';
}