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