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


PHP File::findOne方法代码示例

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


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

示例1: findModel

 /**
  * Finds the File model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return File the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:andreyvaslv,项目名称:crb,代码行数:15,代码来源:FileController.php

示例2: assignFileToRecord

 public function assignFileToRecord($fileId, $recordId, $record_video_type)
 {
     $file = File::findOne($fileId);
     if (!$file) {
         throw new HttpException(500, 'No file found');
     }
     $file->record_id = $recordId;
     $file->record_file_type = $record_video_type;
     return $file->save(false);
 }
开发者ID:vfokov,项目名称:tims2,代码行数:10,代码来源:Media.php

示例3: actionFile

 public function actionFile($id)
 {
     $model = File::findOne(['id' => $id]);
     if ($model === NULL) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     if (file_exists($model->filepath)) {
         //Check to see if the user has permissions
         $ffgs = FileFileGroup::find()->where(['file_id' => $id])->all();
         $ffgs_list = [];
         $found = 0;
         foreach ($ffgs as $f) {
             $ufg = UserFileGroup::find()->where(['file_group_id' => $f->group_id, 'user_id' => \Yii::$app->user->identity->id]);
             if ($ufg !== NULL) {
                 $found = 1;
                 break;
             }
         }
         if ($found == 1) {
             $user = User::findOne(['id' => \Yii::$app->user->identity->id]);
             $dl = new DownloadLog();
             $dl->username = $user->username;
             $dl->email = $user->email;
             $dl->filepath = $model->filepath;
             $dl->download_time = date("Y-m-d H:i:s");
             $dl->filename = $model->filename;
             $dl->user_id = $user->id;
             $dl->save();
             return \Yii::$app->response->sendFile($model->filepath);
         } else {
             throw new HttpException(403, 'You are not allowed to perform this action.');
         }
     } else {
         return $this->redirect(['/site/error']);
     }
 }
开发者ID:rsvancara,项目名称:filedownloader,代码行数:36,代码来源:DownloadController.php

示例4: findModel

 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         if ($model->user_id != Yii::$app->user->id) {
             throw new \yii\web\ForbiddenHttpException();
         }
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:shkrad,项目名称:my_music_storage,代码行数:11,代码来源:FileController.php

示例5: actionPermission

 /**
  * Permissions to files from roles
  */
 public function actionPermission($id)
 {
     if (!Yii::$app->user->can("admin")) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     $file = File::findOne($id);
     $fg = FileGroup::find()->where(['is_deleted' => 0])->all();
     $sufg = FileFileGroup::find()->where(['file_id' => $id])->all();
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         FileFileGroup::deleteAll(['file_id' => $id]);
         if (isset($post['Post']['permission'])) {
             foreach ($post['Post']['permission'] as $perm) {
                 $ffg = new FileFileGroup();
                 $ffg->group_id = $perm;
                 $ffg->file_id = $id;
                 $ffg->save();
             }
         }
         return $this->redirect(['file/view', 'id' => $id]);
     } else {
         return $this->render('permission', ['filemodel' => $file, 'filegroups' => $fg, 'selectedfg' => $sufg]);
     }
 }
开发者ID:rsvancara,项目名称:filedownloader,代码行数:27,代码来源:FilegroupController.php


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