[WORKING] mosDBTable->check

Last reviewed: Not reviewed
phpDocumentor

mosDBTable->check

Checks that current object attributes are valid.

This function may be called at any time but in particular is always called by the mosDBTable->save method to validate the data before saving it to the database. Since these validation tests will be specific to a particular table this function will need to be overridden in the derived class for that table as no tests are performed by the parent class and it will always return true.

When overriding this method you must ensure that it returns a boolean value and that any error message to be returned is placed in $this->_error (see example below).

Syntax

boolean check ( )

Examples

Example: In this example the table contains just two fields: $id and $title.  The $title field must not be empty so the check function performs a simple test to verify this.  This will be called whenever the myTable->save function is called.

class myTable extends mosDBTable {
  var $id=null;
  var $title=null;
 
  function myTable( &$db ) {
    $this->mosDBTable( '#__myTable', 'id', $db );
  }
 
  // Overloaded check function
  function check() {
    // check for valid title
    if (trim( $this->title ) == '') {
      $this->_error = "Title cannot be empty.";
      return false;
    }
 
    return true;
  }
 
}

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )