->validate()

->validate() – check object data, and call objects validation methods.

Synopsis

array $DB_DataObject->validate ( )

Описание

Check all the objects variables to see if they are valid, by default this means is a column an integer or string, if you define methods like validateEmail(), in your extended class then it will be called to validate the row called 'email'. This may be useful if called prior to an update or insert.., to generate error messages.

override this to set up your validation rules.

Return value

array - of validation results or TRUE

Замечание

This function can not be called statically.

the examples below utilize the PEAR validation package

Пример

validate usage

<?php
$person 
= new DataObjects_Person;
$person->get(12);
$person->setFrom($_POST['input']);
$val $person->validate();
if (
$val === TRUE) {
  
$person->update();
} else {
  foreach (
$val as $k=>$v) {
    if (
$v == false) {
      echo 
"There was something wrong with ($k)\n";
    } else {
      echo 
"($k) validated OK\n";
    }
  }
}
?>

validate methods

<?php
/* inside class DataObject_Person */
function validateEmail() {
  return 
Validate::email($this->emailtrue);
}

function 
validateHomepage() {
  return 
Validate::url($this->homepagetrue);
}
function 
validateDate() {
  return 
Validate::date($this->date"%d-%m-%Y", array(01,01,1970), array(01,01,2030));
?>
    Поддержать сайт на родительском проекте КГБ