Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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;


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

It should be add, not validate



1.2k

https://docs.phalconphp.com/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);
    }
}