当前位置: 首页>>代码示例>>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;未经允许,请勿转载。