SHARE
TWEET

robot.php

a guest Mar 21st, 2016 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top