Joomla! Programmierung/Framework/JTable/save

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

ToDo

Inhaltsverzeichnis

[Bearbeiten] Syntax

boolean save ($source, $order_filter='', $ignore='')

[Bearbeiten] Parameters

Argument Data type Description Default
$source array Source array for binding to class vars. See JTable/bind.
$order_filter string Filter for the order updating. See JTable/reorder ''
$ignore mixed An array or space separated list of fields not to bind. See JTable/bind. ''

[Bearbeiten] Returns

TRUE if completely successful, FALSE if partially or not succesful.

[Bearbeiten] Description

JTable::save() - Combines several methods of the JTable Class.

  1. Triggers the bind() method of the object, and binds the $source array to the object. See JTable/bind
  2. Triggers the check() method of the object, and checks if all properties which have been previously been bound to the object are valid. See JTable/check
  3. Triggers the store() method of the object, and updates the row defined by the table key, or inserts a new record if the value of the table key equals 0. See JTable/store
  4. Triggers the checkin() method of the object (only if the table has the columns checked_out and checked_out_time ). See JTable/checkin
  5. If the $order_filter parameter is set, the reorder() method is triggered, compacting the ordering sequence of the selected records. The parameter $order_filter is used to create the $where parameter for the JTable::reorder($where='') method. See JTable/reorder

[Bearbeiten] Preconditions

JTable is an abstract class. You need to write a child class, to use its functionality. See Part 4 of the MVC Tutorial

[Bearbeiten] Source Code

In this particular case a look on the source code is much more self-explainatory than any example.

function save( $source, $order_filter='', $ignore='' )
{
	if (!$this->bind( $source, $ignore )) {
		return false;
	}
	if (!$this->check()) {
		return false;
	}
	if (!$this->store()) {
		return false;
	}
	if (!$this->checkin()) {
		return false;
	}
	if ($order_filter)
	{
		$filter_value = $this->$order_filter;
		$this->reorder( $order_filter ? $this->_db->nameQuote( $order_filter ).' = '.$this->_db->Quote( $filter_value ) : '' );
	}
	$this->setError('');
	return true;
}

[Bearbeiten] Quellcode

Joomla 11.1 JTable->save()

Folder blue.png libraries/joomla

  • Folder red.png database
    • File php.png table.php
  1. public function save($src, $orderingFilter = '', $ignore = '')
  2. {
  3. // Attempt to bind the source to the instance.
  4. if (!$this->bind($src, $ignore)) {
  5. return false;
  6. }
  7.  
  8. // Run any sanity checks on the instance and verify that it is ready for storage.
  9. if (!$this->check()) {
  10. return false;
  11. }
  12.  
  13. // Attempt to store the properties to the database table.
  14. if (!$this->store()) {
  15. return false;
  16. }
  17.  
  18. // Attempt to check the row in, just in case it was checked out.
  19. if (!$this->checkin()) {
  20. return false;
  21. }
  22.  
  23. // If an ordering filter is set, attempt reorder the rows in the table based on the filter and value.
  24. if ($orderingFilter) {
  25. $filterValue = $this->$orderingFilter;
  26. $this->reorder($orderingFilter ? $this->_db->quoteName($orderingFilter).' = '.$this->_db->Quote($filterValue) : '');
  27. }
  28.  
  29. // Set the error to empty and return true.
  30. $this->setError('');
  31.  
  32. return true;
  33. }

[Bearbeiten] See also

Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge