欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

phalcon中model中验证报错

程序员文章站 2022-04-30 22:01:08
...
报错信息
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\PresenceOf given in C:\wamp\www\test\apps\models\Robots.php on line 49

model中的验证代码

use Phalcon\Mvc\Model\Validator\PresenceOf;
use Phalcon\Mvc\Model\Validator\Uniqueness;

public function validation()
    {
        $this->validate(
            new PresenceOf(
                array(
                    "field" => "name",
                    "message" => self::NAME_NOT_EMPTY
                )
            )
        );
        $this->validate(
            new Uniqueness(
                array(
                    'field' => 'code',
                    'message' => self::ERR_CODE_NOT_UNID
                )
            )
        );
        if ($this->validationHasFailed() == true) {
            return false;
        }

        return true;
    }

回复内容:

报错信息

Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\PresenceOf given in C:\wamp\www\test\apps\models\Robots.php on line 49

model中的验证代码

use Phalcon\Mvc\Model\Validator\PresenceOf;
use Phalcon\Mvc\Model\Validator\Uniqueness;

public function validation()
    {
        $this->validate(
            new PresenceOf(
                array(
                    "field" => "name",
                    "message" => self::NAME_NOT_EMPTY
                )
            )
        );
        $this->validate(
            new Uniqueness(
                array(
                    'field' => 'code',
                    'message' => self::ERR_CODE_NOT_UNID
                )
            )
        );
        if ($this->validationHasFailed() == true) {
            return false;
        }

        return true;
    }
相关标签: php phalcon