首頁 >後端開發 >php教程 >phalcon中model中驗證報錯

phalcon中model中驗證報錯

WBOY
WBOY原創
2016-09-28 08:54:071358瀏覽

報錯訊息

<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