PageController.php 1.18 KB
<?php
namespace frontend\controllers;


use common\models\Page;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;


/**
 * Site controller
 */
class  PageController extends Controller
{
    public $layout = '/internal';

    public function actionIndex()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => Page::find()->where(['is_active'=>1]),
            'pagination' => [
                'pageSize' => 16,
            ],

        ]);
        return $this->render('index',[
            'dataProvider' => $dataProvider
        ]);
    }

    public function actionView($translit)
    {

        return $this->render('view', [
            'model' => $this->findModel($translit),
        ]);
    }


    public function actionAbout($translit)
    {

        return $this->render('about_view', [
            'model' => $this->findModel($translit),
        ]);
    }

    protected function findModel($translit)
    {

        if (($model = Page::findOne(["code"=>$translit])) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}