1 | <?php |
||
2 | |||
3 | namespace app\controllers; |
||
4 | |||
5 | use yii\web\NotFoundHttpException; |
||
6 | use yii\filters\{AccessControl, VerbFilter}; |
||
7 | use yii\helpers\ArrayHelper; |
||
8 | use app\models\Article; |
||
9 | |||
10 | /** |
||
11 | * Class ArticleController |
||
12 | * |
||
13 | * @package app\controllers |
||
14 | */ |
||
15 | class ArticleController extends BaseController |
||
16 | { |
||
17 | /** |
||
18 | * @return array |
||
19 | */ |
||
20 | public function behaviors() |
||
21 | { |
||
22 | return ArrayHelper::merge(parent::behaviors(), [ |
||
23 | 'access' => [ |
||
24 | 'class' => AccessControl::class, |
||
25 | 'rules' => [ |
||
26 | [ |
||
27 | 'allow' => true, |
||
28 | 'actions' => ['view'], |
||
29 | 'roles' => ['?', '@'], |
||
30 | ], |
||
31 | ], |
||
32 | ], |
||
33 | 'verbs' => [ |
||
34 | 'class' => VerbFilter::class, |
||
35 | 'actions' => [ |
||
36 | 'view' => ['get'], |
||
37 | ], |
||
38 | ], |
||
39 | ]); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Displays article page. |
||
44 | * |
||
45 | * @param $alias |
||
46 | * @return string |
||
47 | * |
||
48 | * @throws NotFoundHttpException |
||
49 | */ |
||
50 | public function actionView($alias) |
||
51 | { |
||
52 | $model = Article::find()->where([ |
||
53 | 'alias' => $alias |
||
54 | ])->andWhere([ |
||
55 | 'active' => 1 |
||
56 | ])->one(); |
||
57 | |||
58 | if (null === $model) { |
||
59 | throw new NotFoundHttpException('Article not fount with alias = '.$alias.'.'); |
||
60 | } |
||
61 | |||
62 | $this->setMetaParams($model); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
63 | |||
64 | return $this->render('view', [ |
||
65 | 'model' => $model |
||
66 | ]); |
||
67 | } |
||
68 | } |
||
69 |