Back to Table class

Method save

public bool
save
(mixed $src, mixed $orderingFilter = '', mixed $ignore = '')
Method to provide a shortcut to binding, checking and storing a Table instance to the database table.
Parameters
  • array|object $src An associative array or object to bind to the Table instance.
  • string $orderingFilter Filter for the order updating
  • array|string $ignore An optional array or space separated list of properties to ignore while binding.
Returns
  • bool True on success.
Since
  • 1.7.0
Class: Table
Project: Joomla

Method save - Source code

/**
 * Method to provide a shortcut to binding, checking and storing a Table instance to the database table.
 *
 * The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder
 * the table rows based on the filter.  The ordering filter is an instance property name.  The rows that will be reordered
 * are those whose value matches the Table instance for the property specified.
 *
 * @param   array|object  $src             An associative array or object to bind to the Table instance.
 * @param   string        $orderingFilter  Filter for the order updating
 * @param   array|string  $ignore          An optional array or space separated list of properties to ignore while binding.
 *
 * @return  boolean  True on success.
 *
 * @since   1.7.0
 */
public function save($src, $orderingFilter = '', $ignore = '')
{
    // Attempt to bind the source to the instance.
    if (!$this->bind($src, $ignore)) {
        return false;
    }
    // Run any sanity checks on the instance and verify that it is ready for storage.
    if (!$this->check()) {
        return false;
    }
    // Attempt to store the properties to the database table.
    if (!$this->store()) {
        return false;
    }
    // Attempt to check the row in, just in case it was checked out.
    if (!$this->checkIn()) {
        return false;
    }
    // If an ordering filter is set, attempt reorder the rows in the table based on the filter and value.
    if ($orderingFilter) {
        $filterValue = $this->{$orderingFilter};
        $this->reorder($orderingFilter ? $this->_db->quoteName($orderingFilter) . ' = ' . $this->_db->quote($filterValue) : '');
    }
    // Set the error to empty and return true.
    $this->setError('');
    return true;
}