當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Model::hasErrors方法代碼示例

本文整理匯總了PHP中yii\base\Model::hasErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::hasErrors方法的具體用法?PHP Model::hasErrors怎麽用?PHP Model::hasErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\Model的用法示例。


在下文中一共展示了Model::hasErrors方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param Model $model
  * @param string $message
  * @param int $code
  * @param Exception $previous
  */
 public function __construct(Model $model, $message = null, $code = 0, Exception $previous = null)
 {
     $this->model = $model;
     if (is_null($message) && $model->hasErrors()) {
         $message = implode(' ', array_map(function ($errors) {
             return implode(' ', $errors);
         }, $model->getErrors()));
     }
     parent::__construct($message, $code, $previous);
 }
開發者ID:ivan-chkv,項目名稱:yii2-boost,代碼行數:16,代碼來源:InvalidModelException.php

示例2: modelErrors

 public static function modelErrors(Model $model, $message = null, $category = 'application')
 {
     if (!is_null($message)) {
         static::error($message, $category);
     }
     if ($model->hasErrors()) {
         static::error(['class' => get_class($model), 'attributes' => $model->getAttributes(), 'errors' => $model->getErrors()], $category);
     }
 }
開發者ID:ivan-chkv,項目名稱:yii2-kladovka,代碼行數:9,代碼來源:Log.php

示例3: afterValidate

 /**
  * @param Event $event event parameter.
  */
 public function afterValidate($event)
 {
     if (!$this->getIsNeedValidate()) {
         $this->owner->clearErrors($this->attribute);
     }
     if ($this->owner->hasErrors()) {
         $this->addAttempt();
     } else {
         $this->removeAttempts();
     }
 }
開發者ID:heartshare,項目名稱:linuxforum,代碼行數:14,代碼來源:CaptchaBehavior.php

示例4: sendModelError

 /**
  * Helper method to correctly send model erros and add correct response headers.
  *
  * @param ActiveRecordInterface $model
  * @throws ServerErrorHttpException
  * @return array
  */
 public function sendModelError(Model $model)
 {
     if (!$model->hasErrors()) {
         throw new ServerErrorHttpException('Object error for unknown reason.');
     }
     Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
     $result = [];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result[] = ['field' => $name, 'message' => $message];
     }
     return $result;
 }
開發者ID:luyadev,項目名稱:luya-core,代碼行數:19,代碼來源:Controller.php

示例5: validateAttributes

 /**
  * Validates the specified object.
  * @param \yii\base\Model $model the data model being validated
  * @param array|null $attributes the list of attributes to be validated.
  * Note that if an attribute is not associated with the validator, or is is prefixed with `!` char - it will be
  * ignored. If this parameter is null, every attribute listed in [[attributes]] will be validated.
  */
 public function validateAttributes($model, $attributes = null)
 {
     if (is_array($attributes)) {
         $newAttributes = [];
         foreach ($attributes as $attribute) {
             if (in_array($attribute, $this->attributes) || in_array('!' . $attribute, $this->attributes)) {
                 $newAttributes[] = $attribute;
             }
         }
         $attributes = $newAttributes;
     } else {
         $attributes = [];
         foreach ($this->attributes as $attribute) {
             $attributes[] = $attribute[0] === '!' ? substr($attribute, 1) : $attribute;
         }
     }
     foreach ($attributes as $attribute) {
         $skip = $this->skipOnError && $model->hasErrors($attribute) || $this->skipOnEmpty && $this->isEmpty($model->{$attribute});
         if (!$skip) {
             if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                 $this->validateAttribute($model, $attribute);
             }
         }
     }
 }
開發者ID:nanodesu88,項目名稱:yii2,代碼行數:32,代碼來源:Validator.php

示例6: validateAttributes

 /**
  * Validates the specified object.
  * @param \yii\base\Model $object the data object being validated
  * @param array|null $attributes the list of attributes to be validated.
  * Note that if an attribute is not associated with the validator,
  * it will be ignored.
  * If this parameter is null, every attribute listed in [[attributes]] will be validated.
  */
 public function validateAttributes($object, $attributes = null)
 {
     if (is_array($attributes)) {
         $attributes = array_intersect($this->attributes, $attributes);
     } else {
         $attributes = $this->attributes;
     }
     foreach ($attributes as $attribute) {
         $skip = $this->skipOnError && $object->hasErrors($attribute) || $this->skipOnEmpty && $this->isEmpty($object->{$attribute});
         if (!$skip) {
             if ($this->when === null || call_user_func($this->when, $object, $attribute)) {
                 $this->validateAttribute($object, $attribute);
             }
         }
     }
 }
開發者ID:pathman,項目名稱:yii2comm,代碼行數:24,代碼來源:Validator.php

示例7: alertValidation

 /**
  * Prints alert widget containing error summary of validated model
  * @param \yii\base\Model $model
  * @return string
  */
 public static function alertValidation(\yii\base\Model $model)
 {
     return static::alert($model->hasErrors(), ['type' => static::error(), 'body' => Html::errorSummary($model)]);
 }
開發者ID:dlds,項目名稱:yii2-giixer,代碼行數:9,代碼來源:GxFlashHelper.php

示例8: hasErrors

 /**
  * @param null $attribute
  * @return bool
  */
 public function hasErrors($attribute = null)
 {
     if (!empty($this->exceptions)) {
         return true;
     } else {
         return parent::hasErrors($attribute);
     }
 }
開發者ID:ptheofan,項目名稱:yii2-statemachine,代碼行數:12,代碼來源:Context.php

示例9: validateAttributes

 /**
  * Validates the specified object.
  * @param \yii\base\Model $model the data model being validated
  * @param array|null $attributes the list of attributes to be validated.
  * Note that if an attribute is not associated with the validator,
  * it will be ignored.
  * If this parameter is null, every attribute listed in [[attributes]] will be validated.
  */
 public function validateAttributes($model, $attributes = null)
 {
     if (is_array($attributes)) {
         $attributes = array_intersect($this->attributes, $attributes);
         //找出需要被驗證的屬性
     } else {
         $attributes = $this->attributes;
     }
     foreach ($attributes as $attribute) {
         $skip = $this->skipOnError && $model->hasErrors($attribute) || $this->skipOnEmpty && $this->isEmpty($model->{$attribute});
         //判斷如果此屬性有一個驗證錯誤或者屬性值為空時候是否跳過驗證
         if (!$skip) {
             if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                 //驗證一個具體屬性之前的回掉函數
                 $this->validateAttribute($model, $attribute);
             }
         }
     }
 }
開發者ID:great-all,項目名稱:zaizaitvServer,代碼行數:27,代碼來源:Validator.php


注:本文中的yii\base\Model::hasErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。