PHP Classes

File: manuscript/

Recommend this page to a friend!
  Classes of Gjero Krsteski  >  PIMF  >  manuscript/  >  Download  
File: manuscript/
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PIMF
Framework for Web application development
Author: By
Last change: revert wiki pages
add new files
Date: 10 months ago
Size: 1,464 bytes


Class file image Download

Input Validator

Almost every interactive web application needs to validate data. For instance, a registration form probably requires the password to be confirmed. Maybe the e-mail address must be unique. Validations allow you to ensure that only valid data is saved in the database.

Common usage:

Validating incoming data to make sure data is in accordance to business logic rules is easy to do in PIMF.

    // first we check the input-parameters which are send with GET http method.
    $validator = new Pimf\Util\Validator($this->request->fromGet());

    if (!$validator->digit('id') || !$validator->value('id', '>', 0)) {
      throw new Pimf\Controller\Exception('not valid entry for "id"');

Or factorise a validator by set of rules:

Even create a set of rules that will be used to validate each attribute of our model. In PIMF rules are defined in an array format. Let’s take a look:

     $attributes = array(
      'fname'    => 'conan',
      'age'      => 33,
      'birth'    => '12-12-2040',
      'monitor'  => 'sonyT2000',

    $rules = array(
      'fname'   => 'alpha|length[>,0]|lengthBetween[1,9]',
      'age'     => 'digit|value[>,18]|value[==,33]',
      'birth'   => 'length[>,0]|date[mm-dd-yyyy]',
      'monitor' => 'alphaNumeric'

    $validator = Pimf\Util\Validator\Factory::get($attributes, $rules);

For more information send a message to info at phpclasses dot org.