public function actionViewAlbum($id) { if (($model = Album::findOne($id)) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } if ($model->status != Album::TYPE_PUBLIC) { throw new ForbiddenHttpException('You are not allowed to perform this action.'); } return $this->render('viewAlbum', ['model' => $model]); }
<?php use yii\helpers\Url; use yii\helpers\Html; use app\modules\home\models\Album; $albumUrl = Url::toRoute(['/user/view/view-album', 'id' => $model['id']]); $src = Album::getCoverPhoto($model['id'], $model['cover_id']); $name = Html::encode($model['name']); $status = $model['status'] != Album::TYPE_PUBLIC ? '<i class="glyphicon glyphicon-lock"></i>' : ''; ?> <div class="album-img"> <a href="<?php echo $albumUrl; ?> "> <img src="<?php echo $src; ?> " class="album-cover" alt="album-cover"> </a> </div> <div class="album-info"> <div class="album-desc"> <div class="album-desc-side"><?php echo $status; ?> </div> <div class="album-tit"> <?php echo Html::a($name, $albumUrl, ['class' => 'album-name']); ?>
/** * Finds the Album model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Album the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Album::findOne($id)) !== null) { if ($model->created_by !== Yii::$app->user->id) { throw new ForbiddenHttpException('You are not allowed to perform this action.'); } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionViewAlbum($id) { if (($model = Album::findOne($id)) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } if ($model->status !== Album::TYPE_PUBLIC || $model->status !== Album::TYPE_PUBLIC && $model->created_by !== Yii::$app->user->id) { throw new ForbiddenHttpException('You are not allowed to perform this action.'); } $user = $this->findModel($model->created_by); return $this->render('/user/viewAlbum', ['model' => $model, 'user' => $user]); }
<div class="e-album-all"> <div class="panel panel-default"> <div class="panel-heading"> <?php echo Yii::t('app', 'Albums'); ?> <?php echo Html::a(Yii::t('app', 'More'), ['/explore/photos'], ['class' => 'pull-right']); ?> </div> <div class="panel-body"> <div class="row"> <?php if ($this->beginCache('explore-album', ['duration' => 3600])) { foreach ($albums as $album) { $coverSrc = Album::getCoverPhoto($album['id']); $link = Url::toRoute(['/explore/view-album', 'id' => $album['id']]); ?> <div class="album-item col-md-3 col-sm-6"> <div class="album-img"> <a href="<?php echo $link; ?> "> <img src="<?php echo $coverSrc; ?> " class="album-cover" alt="album-cover"> </a> </div> <div class="album-info">