當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。