Strange behavior model validation

i have mysql unique filed phone and validation method

public function validation()
    {
        $validator = new Validation();

        $validator->add('phone', new Uniqueness([
            'message' => 'phone exist',
        ]));

        return $this->validate();
    }

after post form receiving a message - Wrong number of parameters

Why?

phalcon 2.0.9



67.7k

hey, i am not sure since they changed vlaidations in 2.1.x

can you check with

return $this->validate($validator);


11.6k
edited Feb '16

not work

fatal: PHP Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\Mvc\Model\ValidatorInterface

and

public function validation()
    {
        $this->validate(new Uniqueness([
            'field'   => 'phone',
            'message' => 'phone exist'
        ]));

        return $this->validationHasFailed() != true;
    }

not work too

HP Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\Mvc\Model\ValidatorInterface

hey, i am not sure since they changed vlaidations in 2.1.x

can you check with

return $this->validate($validator);


67.7k
edited Feb '16

aham, got it, you saw the wrong demo. your example is for 2.1.x


 public function validation()
  {
      $this->validate(new Uniqueness(array(
          "field"   => "email",
          "message" => "Value of field 'email' is already present in another record"
      )));
      if ($this->validationHasFailed() == true) {
          return false;
      }
  }

https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Validator_Uniqueness.html

https://docs.phalconphp.com/en/latest/reference/models.html#validating-data-integrity



11.6k
edited Feb '16

i show code for 2.x too

and this code not work too

aham, got it, you saw the wrong demo. your example is for 2.1.x


public function validation()
 {
     $this->validate(new Uniqueness(array(
         "field"   => "email",
         "message" => "Value of field 'email' is already present in another record"
     )));
     if ($this->validationHasFailed() == true) {
         return false;
     }
 }

https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Validator_Uniqueness.html

https://docs.phalconphp.com/en/latest/reference/models.html#validating-data-integrity



67.7k
edited Feb '16

ah yeah... didnt pay enought attention..

hmm i have seen this error when i was creating my own validator... sohuld be working btw ...

if you try somethign as stupid as


$this->validate(new \Phalcon\Mvc\Model\Validator\Uniqueness(array(
          "field"   => "email",
          "message" => "Value of field 'email' is already present in another record"
)));