webCOMAND

cObject::validate()

Perform the default validation process on the object.  If validation fails, a validation_exception is thrown.  This method is called when approve() or save() is called, but notably not when store() is called.

Prototype

boolean validate(array $options = [])

Parameters

  • options - Associative array of options passed to validate, typically by approve() and save(), which may include the following keys.
    • SuppressErrors - TRUE if errors should not be logged.  Default is FALSE.
    • SuppressLogs - TRUE if all events should not be logged.  Default is FALSE.
    • TemplateOnly - TRUE to skip field validations and only process the content type's validate template.  Default is FALSE.
    • ValidateReferences - TRUE to follow and validate objects referenced by forward reference fields, recursively.  Default is FALSE.

Return

TRUE if the object was valid.  Otherwise a validation_exception is thrown (FALSE is not returned).

Exceptions

  • validation_exception - thrown if object is not valid.
  • exception - thrown if some another type of exception is thrown during processing.

Example

Call validate() on an object directly.

$repo = \comand::repo();
$pub_proc = $repo->new_object('PublicationProcedure');
try {
    $pub_proc->validate();
} catch(\io_comand\validation_exception $e) {
    echo("Validation Failed: " . $e->getMessage());
}

Custom Validation Example

Augment the default validation behavior for MyContact object with a custom validate() method.

class MyContact extends \io_comand_repo\models\Content {
    function validate(array $options = []) {
        if($this->FirstName == '') {
            throw new \io_comand\validation_exception("No First Name.");
        }
        return parent::validate($options);
    }
}

Related

Validations