当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::getErrors方法代码示例

本文整理汇总了PHP中yii\base\Model::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getErrors方法的具体用法?PHP Model::getErrors怎么用?PHP Model::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\base\Model的用法示例。


在下文中一共展示了Model::getErrors方法的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: readValue

 /**
  * @param Model $model
  * @param string $attribute
  */
 private function readValue($model, $attribute)
 {
     $model->{$attribute} = $this->prompt(mb_convert_case($attribute, MB_CASE_TITLE, 'utf-8') . ':', ['validator' => function ($input, &$error) use($model, $attribute) {
         $model->{$attribute} = $input;
         if ($model->validate([$attribute])) {
             return true;
         } else {
             $error = implode(',', $model->getErrors($attribute));
             return false;
         }
     }]);
 }
开发者ID:GT-Volk,项目名称:ManagerOrganizer,代码行数:16,代码来源:UsersController.php

示例3: populateErrors

 /**
  * @param \yii\base\Model
  * @param string $default_attribute
  * @param array $attributes_map
  */
 public function populateErrors(\yii\base\Model $Model, $default_attribute, $attributes_map = [])
 {
     $errors = $Model->getErrors();
     foreach ($errors as $attribute => $messages) {
         $attribute = isset($attributes_map[$attribute]) ? $attributes_map[$attribute] : $attribute;
         if (false === $this->hasProperty($attribute)) {
             if (!method_exists($this, 'hasAttribute')) {
                 $attribute = $default_attribute;
             } elseif (false === $this->hasAttribute($attribute)) {
                 $attribute = $default_attribute;
             }
         }
         foreach ($messages as $mes) {
             $this->addError($attribute, $mes);
         }
     }
 }
开发者ID:cookyii,项目名称:base,代码行数:22,代码来源:PopulateErrorsTrait.php

示例4: throwModel

 /**
  * @param Model $model
  * @throws JqException
  */
 public static function throwModel($model)
 {
     $errors = $model->getErrors();
     if (empty($errors)) {
         return;
     }
     $message = '';
     foreach ($errors as $name => $error) {
         if (!is_array($error)) {
             continue;
         }
         $message .= $name . ': ';
         foreach ($error as $e) {
             $message .= $e . '; ';
         }
     }
     throw new self($message);
 }
开发者ID:andriell,项目名称:yii2-extensions,代码行数:22,代码来源:JqException.php

示例5: validateAttributes

 /**
  * Валидация атрибутов.
  *
  * На вход передается модель для валидации и массив значений для валидации.
  * Массив значений должен иметь следующий формат:
  * ```php
  * array(
  *     '<attribute1>' => array(
  *         array(
  *             'value' => <mixed>, // значение для валидации
  *             'isValid' => <boolean>, // true, если значение должно проходить валидацию
  *         ),
  *     ),
  * )
  * ```
  *
  * Проверяет, что атрибут либо должен проходить проверку валидации, либо не должен.
  *
  * @param Model $model проверяемая модель
  * @param array $attributes массив значений атрибутов для валидации
  */
 protected function validateAttributes(Model $model, $attributes)
 {
     foreach ($attributes as $attribute => $values) {
         $attributeTitle = $model->getAttributeLabel($attribute);
         foreach ($values as $v) {
             $value = $v['value'];
             $isValid = $v['isValid'];
             $model->{$attribute} = $value;
             if ($isValid) {
                 $message = $attributeTitle . ' validation error: ' . implode("\n", $model->getErrors($attribute));
                 $message .= "\nAsserting value: " . print_r($value, true);
                 $this->assertTrue($model->validate([$attribute]), $message);
             } else {
                 $message = $attributeTitle . ' must be invalid' . "\n";
                 $message .= 'Asserting value: ' . print_r($value, true);
                 $this->assertFalse($model->validate([$attribute]), $message);
             }
         }
     }
 }
开发者ID:internet-design,项目名称:yii2-svk-tests,代码行数:41,代码来源:ModelTestTrait.php

示例6: validate

 /**
  * Validates one or several models and returns an error message array indexed by the attribute IDs.
  * This is a helper method that simplifies the way of writing AJAX validation code.
  *
  * For example, you may use the following code in a controller action to respond
  * to an AJAX validation request:
  *
  * ```php
  * $model = new Post;
  * $model->load($_POST);
  * if (Yii::$app->request->isAjax) {
  *     Yii::$app->response->format = Response::FORMAT_JSON;
  *     return ActiveForm::validate($model);
  * }
  * // ... respond to non-AJAX request ...
  * ```
  *
  * To validate multiple models, simply pass each model as a parameter to this method, like
  * the following:
  *
  * ```php
  * ActiveForm::validate($model1, $model2, ...);
  * ```
  *
  * @param Model $model the model to be validated
  * @param mixed $attributes list of attributes that should be validated.
  * If this parameter is empty, it means any attribute listed in the applicable
  * validation rules should be validated.
  *
  * When this method is used to validate multiple models, this parameter will be interpreted
  * as a model.
  *
  * @return array the error message array indexed by the attribute IDs.
  */
 public static function validate($model, $attributes = null)
 {
     $result = [];
     if ($attributes instanceof Model) {
         // validating multiple models
         $models = func_get_args();
         $attributes = null;
     } else {
         $models = [$model];
     }
     /* @var $model Model */
     foreach ($models as $model) {
         $model->validate($attributes);
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[Html::getInputId($model, $attribute)] = $errors;
         }
     }
     return $result;
 }
开发者ID:sadiqhirani,项目名称:yii2,代码行数:53,代码来源:ActiveForm.php

示例7: addModelErrors

 /**
  * @param \yii\base\Model $model
  */
 public static function addModelErrors($model)
 {
     $errors = $model->getErrors();
     self::addError(self::flatten($errors));
 }
开发者ID:iw-reload,项目名称:iw,代码行数:8,代码来源:FlashWidget.php

示例8: formatModelErrors

 /**
  * @param Model $model
  * @param string $glue
  * @return string
  */
 public static function formatModelErrors(Model $model, $glue = PHP_EOL)
 {
     return implode($glue, array_map(function ($item) {
         return is_array($item) ? array_pop($item) : $item;
     }, $model->getErrors()));
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:11,代码来源:Helper.php

示例9:

 function __construct(\yii\base\Model $model)
 {
     parent::__construct('model.validation.error', null, $model->getErrors());
 }
开发者ID:filsh,项目名称:yii2-wamp,代码行数:4,代码来源:ModelValidationException.php


注:本文中的yii\base\Model::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。