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

model validate return 503 Bad Gateway

The use of validation in the model returns a 503 error
Delete the validator can run why?

in phalcon3.01, php7

model code:

<?php

namespace Frontend\Models;

use Phalcon\Validation,
    Phalcon\Validation\Validator\Uniqueness;

class Spider extends ModelBase
{

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

        $validator->validate(
            "surl",
            new Uniqueness()
        );

        return $this->validate($validator);
    }

}

mysql table:

CREATE TABLE `spider` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `s` varchar(200) NOT NULL DEFAULT ''',
  `surl` varchar(250) NOT NULL DEFAULT ''',
  `stitle` varchar(250) NOT NULL DEFAULT '',
  `saddtime` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


145.0k
Accepted
answer
  $validator->validate(
            "surl",
            new Uniqueness()
        );

It should be add, not validate



3.0k

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

The code on the site is like this:
Are they wrong?

<?php

namespace Store\Toys;

use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Uniqueness;
use Phalcon\Validation\Validator\InclusionIn;

class Robots extends Model
{
    public function validation()
    {
        $validator = new Validation();

        $validator->validate(
            "type",
            new InclusionIn(
                [
                    "domain" => [
                        "Mechanical",
                        "Virtual",
                    ]
                ]
            )
        );

        $validator->validate(
            "name",
            new Uniqueness(
                [
                    "message" => "The robot name must be unique",
                ]
            )
        );

        return $this->validate($validator);
    }
}