Actions

Difference between revisions of "JTable/save"

From Joomla! Documentation

(New page: {{review}} ===Syntax=== ''boolean'' <nowiki> save ($source, $order_filter='', $ignore='')</nowiki> === Parameters === {| class="wikitable" !Argument !Data type !Description !Default |- |...)
 
(Source Code)
 
(One intermediate revision by one user not shown)
Line 23: Line 23:
 
|mixed
 
|mixed
 
|An array or space separated list of fields not to bind. See [[JTable/bind]].
 
|An array or space separated list of fields not to bind. See [[JTable/bind]].
 +
|<nowiki>''</nowiki>
 
|}
 
|}
  
Line 34: Line 35:
 
# 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]]
 
# 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]]
 
# Triggers the checkin() method of the object (only if the table has the columns <code> checked_out </code> and <code> checked_out_time </code>). See [[JTable/checkin]]
 
# Triggers the checkin() method of the object (only if the table has the columns <code> checked_out </code> and <code> checked_out_time </code>). See [[JTable/checkin]]
# If the <code>$order_filter</code> parameter is set, the reorder() method is triggered, compacting the ordering sequence of the selected records. See [[JTable/reorder]]
+
# If the <code>$order_filter</code> parameter is set, the reorder() method is triggered, compacting the ordering sequence of the selected records. The parameter <code>$order_filter</code> is used to create the <code> $where </code> parameter for the <code><nowiki>JTable::reorder($where='')</nowiki></code> method. See [[JTable/reorder]]
 
=== Preconditions ===
 
=== Preconditions ===
 
JTable is an abstract class. You need to write a child class, to use its functionality. See [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Part 4 of the MVC Tutorial]]
 
JTable is an abstract class. You need to write a child class, to use its functionality. See [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Part 4 of the MVC Tutorial]]
 +
 +
=== Source Code ===
 +
In this particular case a look on the source code is much more self-explainatory than any example.
 +
 +
<source lang="php">
 +
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;
 +
}
 +
</source>
  
 
===See also===
 
===See also===
 
* [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Creating a JTable Child Class (MVC Tutorial Part 4)]]
 
* [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Creating a JTable Child Class (MVC Tutorial Part 4)]]
 +
* [http://api.joomla.org/Joomla-Framework/Table/JTable.html#save API Reference on JTable::save()]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JTable]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JTable]]</noinclude>

Latest revision as of 16:50, 25 November 2008

Copyedit.png
This Article Needs Your Help

This article is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


Contents

Syntax

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

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. ''

Returns

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

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

Preconditions

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

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;
}

See also