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


PHP Model::getFirstErrors方法代码示例

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


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

示例1: getErrors

 /**
  * @return array
  */
 public function getErrors()
 {
     if (empty($this->_errors)) {
         foreach ($this->_model->getFirstErrors() as $name => $message) {
             $this->_errors[] = ['field' => $name, 'message' => $message];
         }
     }
     return $this->_errors;
 }
开发者ID:mole-chen,项目名称:yii2,代码行数:12,代码来源:ValidateException.php

示例2: serializeModelErrors

 /**
  * Serializes the validation errors in a model.
  * @param Model $model
  * @return array the array representation of the errors
  */
 protected function serializeModelErrors($model)
 {
     Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
     $result = [];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result[] = ['field' => $name, 'message' => $message];
     }
     return $result;
 }
开发者ID:dextercool,项目名称:yii2-easyui,代码行数:14,代码来源:Serializer.php

示例3: 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

示例4: getModelErrors

 /**
  * Helper function
  *
  * @param \yii\base\Model $model
  *
  * @return array
  * @todo breaks DRY. Think of the best way to implement.
  */
 protected function getModelErrors($model)
 {
     $errors = [];
     foreach ($model->getFirstErrors() as $error) {
         $errors[] = $error;
     }
     return $errors;
 }
开发者ID:2amigos,项目名称:yii2-file-upload-widget,代码行数:16,代码来源:FileDeleteAction.php

示例5: serializeModelErrors

 /**
  * Serializes the validation errors in a model.
  * @param Model $model
  * @return array the array representation of the errors
  */
 protected function serializeModelErrors($model)
 {
     $this->response->setStatusCode(422, 'Data Validation Failed.');
     $result = [];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result[] = ['field' => $name, 'message' => $message];
     }
     return $result;
     // return [
     //     'success'=>0,
     //     'status'=>\Yii::$app->response->getStatusCode(),
     //     $this->collectionEnvelope=>$result
     // ];
 }
开发者ID:pointdnd,项目名称:yii2-modular,代码行数:19,代码来源:Serializer.php

示例6: validateModel

 /**
  * @param \yii\base\Model $model
  * @param array $attributes
  * @return bool
  */
 private function validateModel(\yii\base\Model $model, array $attributes)
 {
     $model->attributes = $attributes;
     if ($model->validate() !== true) {
         $this->errors[] = $model->getFirstErrors();
         return false;
     }
     return true;
 }
开发者ID:anmoroz,项目名称:yii2-analytics,代码行数:14,代码来源:ElasticaQueryBuilder.php

示例7: exportErrors

 /**
  * Exports the model validation errors.
  * @param Model $model
  * @return array
  */
 public function exportErrors($model)
 {
     $result = ['code' => $this->validationErrorCode, 'message' => $this->validationErrorMessage, 'errors' => []];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result['errors'][] = ['field' => $name, 'message' => $message];
     }
     return $result;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:13,代码来源:ModelSerializer.php

示例8: serializeModelErrors

 /**
  * Serializes the validation errors in a model.
  * @param Model $model
  * @return array the array representation of the errors
  */
 protected function serializeModelErrors($model)
 {
     $this->response->setStatusCode(422, 'Data Validation Failed.');
     $result = [];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result[] = ['source' => ['pointer' => "/data/attributes/{$name}"], 'detail' => $message];
     }
     return $result;
 }
开发者ID:tuyakhov,项目名称:yii2-json-api,代码行数:14,代码来源:Serializer.php


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