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


PHP ActiveRecord::getErrors方法代码示例

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


在下文中一共展示了ActiveRecord::getErrors方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     foreach ($this->model->getErrors() as $attribute => $messages) {
         foreach ($messages as $key => $message) {
             $this->options['id'] = 'error-' . $attribute . '-' . $key;
             echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
         }
     }
 }
开发者ID:zelenin,项目名称:yii2-widgets,代码行数:12,代码来源:Error.php

示例2: addErrorMessagesFromModel

 /**
  * @param ActiveRecord $model
  */
 public function addErrorMessagesFromModel(ActiveRecord $model)
 {
     foreach ($model->getErrors() as $fieldWithErrors) {
         foreach ($fieldWithErrors as $error) {
             $this->addMessage(null, $error, Message::ALERT);
         }
     }
 }
开发者ID:pbabilas,项目名称:bcode,代码行数:11,代码来源:AbstractController.php

示例3: populateErrors

 /**
  * @param \yii\db\ActiveRecord $Model
  * @param string $default_attribute
  */
 public function populateErrors(\yii\db\ActiveRecord $Model, $default_attribute)
 {
     $errors = $Model->getErrors();
     foreach ($errors as $key => $messages) {
         $attribute = $key;
         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:rmrevin,项目名称:yii2-application,代码行数:21,代码来源:PopulateErrorsTrait.php

示例4: populateErrors

 /**
  * @param ActiveRecord $model
  * @param string $defaultAttribute
  * @param array $attributesMap
  */
 public function populateErrors(ActiveRecord $model, $defaultAttribute, $attributesMap = [])
 {
     /** @var Model $this */
     $errors = $model->getErrors();
     foreach ($errors as $attribute => $messages) {
         $attribute = isset($attributesMap[$attribute]) ? $attributesMap[$attribute] : $attribute;
         if (false === $this->hasProperty($attribute)) {
             if (!method_exists($this, 'hasAttribute')) {
                 $attribute = $defaultAttribute;
             } elseif (false === $this->hasAttribute($attribute)) {
                 $attribute = $defaultAttribute;
             }
         }
         foreach ($messages as $mes) {
             $this->addError($attribute, $mes);
         }
     }
 }
开发者ID:voskobovich,项目名称:yii2-base-toolkit,代码行数:23,代码来源:ModelTrait.php

示例5: throwInvalidModelException

 /**
  * Converts the model validation errors to a readable format an throws it as an exception
  * @param ActiveRecord $model
  * @throws Exception
  */
 protected function throwInvalidModelException($model)
 {
     $errorMessage = Yii::t('language', 'Invalid model "{model}":', ['model' => $model->className()]);
     foreach ($model->getErrors() as $attribute => $errors) {
         $errorMessage .= "\n {$attribute}: " . join(', ', $errors);
     }
     throw new Exception($errorMessage);
 }
开发者ID:maxxer,项目名称:yii2-translate-manager,代码行数:13,代码来源:ImportForm.php

示例6: runCrudAction

 /**
  * Run Create/Read/Update/Delete action
  *
  * Set error flash and throw Exception, if action failed
  * Return nothing if action succeed
  *
  * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[] $model
  * @return void
  * @throws \Exception
  */
 protected function runCrudAction($model)
 {
     if ($model instanceof Model) {
         if (!call_user_func([$model, $this->modelAction])) {
             if ($model->hasErrors()) {
                 $this->flashError = [];
                 foreach ($model->getErrors() as $errors) {
                     $this->flashError = array_merge($this->flashError, $errors);
                 }
             }
             throw new \Exception($this->flashError ? VarDumper::dumpAsString($this->flashError) : 'Unknown error');
         }
         return;
     }
     foreach ($model as $concreteModel) {
         $this->runCrudAction($concreteModel);
     }
 }
开发者ID:yii2-tools,项目名称:yii2-crud,代码行数:28,代码来源:Action.php

示例7: chainDelete

 /**
  * @param ActiveRecord $model
  * @return ActiveRecord
  * @throws \yii\web\ServerErrorHttpException
  */
 protected function chainDelete($model)
 {
     if (!$model->delete()) {
         if (YII_DEBUG) {
             Yii::$app->response->statusCode = 500;
             Yii::$app->response->format = Response::FORMAT_JSON;
             var_dump($model->getErrors());
             Yii::$app->end();
         }
         throw new ServerErrorHttpException('Do not able to save the model.');
     }
     return $model;
 }
开发者ID:laojiu,项目名称:yii2-rest,代码行数:18,代码来源:RestAction.php

示例8: addValidationErrors

 /**
  * @param \yii\db\ActiveRecord $model
  */
 public function addValidationErrors($model)
 {
     $keyValue = $this->composeKey($model->getPrimaryKey(true));
     $this->_errors['validation'][$keyValue] = $model->getErrors();
 }
开发者ID:tigrov,项目名称:yii2-kendoui,代码行数:8,代码来源:Action.php


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