ice framework documentation ice doc v1.10.1
Class Ice

Validation

Methods
Methods Details
  • public function getDi()

  • public function getData()

  • public function setRules(variable $rules)

  • public function getRules()

  • public function setFilters(variable $filters)

  • public function setLabels(variable $labels)

  • public function setAliases(variable $aliases)

  • public function setTranslate(variable $translate)

  • public function getTranslate()

  • public function setHumanLabels(variable $humanLabels)

  • public function __construct(array $data)

    Validation constructor. Fetch Di and set the data if given.
  • public function resolve(string $alias, string $field, array $options)

    Resolve one rule.
  • public function rule(string $field, variable $validators, variable $options)

    Add one rule.
    
          $validation = new Ice\Validation();
         
          $validation->rule('email', 'required|email');
          $validation->rule('content', [
              'length' => [
                  'max' => 1000,
                  'messageMin' => 'Too long!',
                  'label' => 'Desctiption'
              ]
          ]);
         
  • public function rules(array $validators, bool $merge)

    Add multiple rules at once.
    
          $validation = new Ice\Validation();
         
          $validation->rules([
              'username' => 'required|length:4,24|notIn:admin,user,root|unique:users',
              'password'  => 'required|length:5,32',
              'repeatPassword'  => 'same:password',
              'email'  => 'email',
              'status'  => 'required|digit|in:0,1,2',
              'website'  => 'url',
              'title'  => 'length:,100',
              'age'  => 'required|between:18,21',
          ]);
         
  • public function validate(array $data, bool $clear)

    Validate the data.
  • public function valid()

    Check if validation passed.
  • public function hasValue(string $field)

    Whether or not a value exists by field.
  • public function getValue(string $field, bool $filtered)

    Get a value by field.
  • public function getValues(variable $fields, bool $filtered)

    Get the values by fields.
    Values are automatically filtered out if filters have been setted.
    
          // Get value for one field
          $validation->getValues('password');
         
          // Get values for multiple fields
          $validation->getValues(['fullName', 'about']);
         
          // Get all values
          $validation->getValues();
         
  • public function getLabel(string $field)

    Get the label of a field.
    Humanize a label if humanLabels attribute and filter service is available
  • public function setDefaultMessages(array $messages)

    Set the default messages.
  • public function getDefaultMessage(string $type)

    Get a default message for the type.
  • public function addMessage(string $field, string $message)

    Add a message to the field.
  • public function getMessages()

    Get the validation's messages.
  • internal function zephir_init_properties_Ice_Validation()