本文整理汇总了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.');
}
}
示例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);
}
示例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']);
}
}
示例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.');
}
}
示例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]);
}
}