首页 >后端开发 >php教程 >phalcon中model中验证报错

phalcon中model中验证报错

WBOY
WBOY原创
2016-09-28 08:54:071353浏览

报错信息

<code>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</code>

model中的验证代码

<code>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;
    }</code>

回复内容:

报错信息

<code>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</code>

model中的验证代码

<code>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;
    }</code>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn