Issues (1313)

controllers/PageController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace app\controllers;
4
5
use Yii;
6
use yii\data\Pagination;
7
use yii\web\NotFoundHttpException;
8
use yii\filters\{AccessControl, VerbFilter};
9
use yii\helpers\ArrayHelper;
10
use app\models\{Page, Article};
11
12
/**
13
 * Class PageController
14
 *
15
 * @package app\controllers
16
 */
17
class PageController extends BaseController
18
{
19
    /**
20
     * @return array
21
     */
22
    public function behaviors()
23
    {
24
        return ArrayHelper::merge(parent::behaviors(), [
25
            'access' => [
26
                'class' => AccessControl::class,
27
                'rules' => [
28
                    [
29
                        'allow' => true,
30
                        'actions' => ['view'],
31
                        'roles' => ['?', '@'],
32
                    ],
33
                ],
34
            ],
35
            'verbs' => [
36
                'class' => VerbFilter::class,
37
                'actions' => [
38
                    'view' => ['get'],
39
                ],
40
            ],
41
        ]);
42
    }
43
44
    /**
45
     * Displays Ppage.
46
     *
47
     * @param $alias
48
     * @return string
49
     *
50
     * @throws NotFoundHttpException
51
     */
52
    public function actionView($alias)
53
    {
54
        $model = Page::find()->where([
55
            'alias' => $alias
56
        ])->andWhere([
57
            'active' => 1
58
        ])->one();
59
60
        if (null === $model) {
61
            throw new NotFoundHttpException('Page not fount with alias = '.$alias.'.');
62
        }
63
64
        $this->setMetaParams($model);
0 ignored issues
show
It seems like $model can also be of type array; however, parameter $model of app\controllers\BaseController::setMetaParams() does only seem to accept null|yii\db\ActiveRecord, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $this->setMetaParams(/** @scrutinizer ignore-type */ $model);
Loading history...
65
66
        $articlesQuery = Article::find()->where([
67
            'pageId' => $model->id
68
        ])->andWhere([
69
            'active' => 1
70
        ]);
71
72
        $pagination = new Pagination([
73
            'totalCount' => $articlesQuery->count(),
74
            'defaultPageSize' => Yii::$app->params['defaultPageSize']
75
        ]);
76
77
        return $this->render('view', [
78
            'model' => $model,
79
            'pagination' => $pagination,
80
            'articles' => $articlesQuery->offset($pagination->offset)
81
                ->limit($pagination->limit)
82
                ->all()
83
        ]);
84
    }
85
}
86