PageController.php 1.84 KB
<?php

namespace frontend\modules\page\controllers;

use Yii;
use yii\filters\VerbFilter;
use yii\web\NotFoundHttpException;

//
use thread\actions\RecordView;
//
use frontend\components\BaseController;
use frontend\modules\page\models\Page;

/**
 * Class PageController
 *
 * @package frontend\modules\page\controllers
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c), Thread
 */
class PageController extends BaseController
{
    public $title = "Page";
    public $layout = "@app/layouts/base";
    public $defaultAction = 'index';

    /**
     *
     */
    public function init()
    {
        parent::init();

        $this->breadcrumbs = [
            [
                'label' => Yii::t('page', 'Pages')
            ]
        ];
    }

    /**
     * @return array
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::class,
                'actions' => [
                    'index' => ['get'],
                    'contacts' => ['get'],
                    'view' => ['get'],
                ],
            ]
        ];
    }

    /**
     * @return array
     */
    public function actions()
    {
        $page = Page::findByAlias(Yii::$app->request->get('alias', ''))->asArray()->one();
        if(($page) && $page['id'] == Page::RESULT_PAGE_ID && Yii::$app->getUser()->isGuest){
            throw new NotFoundHttpException();
        }
        return [
            'view' => [
                'class' => RecordView::class,
                'modelClass' => Page::class,
                'methodName' => 'getByAlias',
                'layout' => '@app/layouts/base'
            ]
        ];
    }

    /**
     *
     * @return string
     */
    public function actionIndex()
    {
        $this->layout = "/start";
        return $this->run('view', ['alias' => 'start']);
    }


}