Guest User

robot.php

a guest
Mar 21st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. use Phalcon\Mvc\Model;
  4. use Phalcon\Mvc\Model\Message;
  5. use Phalcon\Mvc\Model\Validator\Uniqueness;
  6. use Phalcon\Mvc\Model\Validator\InclusionIn;
  7.  
  8. class Robots extends Model
  9. {
  10.     public function validation()
  11.     {
  12.         // Type must be: droid, mechanical or virtual
  13.         $this->validate(
  14.             new InclusionIn(
  15.                 array(
  16.                     "field"  => "type",
  17.                     "domain" => array(
  18.                         "droid",
  19.                         "mechanical",
  20.                         "virtual"
  21.                     )
  22.                 )
  23.             )
  24.         );
  25.  
  26.         // Robot name must be unique
  27.         $this->validate(
  28.             new Uniqueness(
  29.                 array(
  30.                     "field"   => "name",
  31.                     "message" => "The robot name must be unique"
  32.                 )
  33.             )
  34.         );
  35.  
  36.         // Year cannot be less than zero
  37.         if ($this->year < 0) {
  38.             $this->appendMessage(new Message("The year cannot be less than zero"));
  39.         }
  40.  
  41.         // Check if any messages have been produced
  42.         if ($this->validationHasFailed() == true) {
  43.             return false;
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment