當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DynamicModel::getErrors方法代碼示例

本文整理匯總了PHP中yii\base\DynamicModel::getErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP DynamicModel::getErrors方法的具體用法?PHP DynamicModel::getErrors怎麽用?PHP DynamicModel::getErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\DynamicModel的用法示例。


在下文中一共展示了DynamicModel::getErrors方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * 
  * @return type
  * @throws BadRequestHttpException
  */
 public function run()
 {
     if (Yii::$app->request->isPost) {
         if (!empty($this->getParamName) && Yii::$app->getRequest()->get($this->getParamName)) {
             $this->paramName = Yii::$app->getRequest()->get($this->getParamName);
         }
         $file = UploadedFile::getInstanceByName($this->paramName);
         $model = new DynamicModel(compact('file'));
         $model->addRule('file', $this->_validator, $this->validatorOptions);
         if ($model->validate()) {
             if ($this->unique === true) {
                 $model->file->name = uniqid() . (empty($model->file->extension) ? '' : '.' . $model->file->extension);
             }
             $result = $model->file->saveAs($this->path . $model->file->name) ? ['key' => $model->file->name, 'caption' => $model->file->name, 'name' => $model->file->name] : ['error' => 'Can\'t upload file'];
         } else {
             $result = ['error' => $model->getErrors()];
         }
         if (Yii::$app->getRequest()->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
         }
         return $result;
     } else {
         throw new BadRequestHttpException('Only POST is allowed');
     }
 }
開發者ID:filamentv,項目名稱:yii2-app,代碼行數:30,代碼來源:UploadAction.php

示例2: actionUploadAvatar

 public function actionUploadAvatar()
 {
     if (Yii::$app->user->isGuest) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = new DynamicModel(['image']);
     $model->addRule('image', 'file', ['skipOnEmpty' => false, 'extensions' => 'png, jpg']);
     if (Yii::$app->request->isPost) {
         $model->image = UploadedFile::getInstanceByName('image');
         if ($model->validate()) {
             try {
                 return AvatarHelper::saveAvatar($model->image);
             } catch (Exception $exc) {
                 Yii::$app->response->statusCode = 400;
                 return Yii::t('yee', 'An unknown error occurred.');
             }
         } else {
             $errors = $model->getErrors();
             Yii::$app->response->statusCode = 400;
             return $model->getFirstError(key($errors));
         }
     }
     return;
 }
開發者ID:yeesoft,項目名稱:yii2-yee-auth,代碼行數:25,代碼來源:DefaultController.php


注:本文中的yii\base\DynamicModel::getErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。