当前位置: 首页>>代码示例>>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;未经允许,请勿转载。