We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



85.5k

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

can you check with

return $this->validate($validator);


25.0k
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);


85.5k
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.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Validator_Uniqueness.html

https://docs.phalcon.io/en/latest/reference/models.html#validating-data-integrity



25.0k
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.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Validator_Uniqueness.html

https://docs.phalcon.io/en/latest/reference/models.html#validating-data-integrity



85.5k
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"
)));