You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

7 years ago
<?php
namespace common\modules\pages\controllers;
7 years ago
use common\modules\pages\repositories\read\PageReadRepository;
use frontend\components\FrontendController;
7 years ago
use yii\web\NotFoundHttpException;
use yii\filters\AccessControl;
class PageController extends FrontendController
7 years ago
{
3 years ago
private PageReadRepository $pages;
7 years ago
public $layout = 'page';
7 years ago
public function __construct($id, $module, PageReadRepository $pages, $config = [])
{
parent::__construct($id, $module, $config);
3 years ago
$this->pages = $pages;
7 years ago
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['view'],
'allow' => true,
//'roles' => ['Pages'],
],
[
'actions' => ['preview'],
'allow' => true,
'roles' => ['PagesManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
7 years ago
/**
* @param $id
*
3 years ago
* @return string
7 years ago
* @throws NotFoundHttpException
* @internal param string $slug
*/
3 years ago
public function actionView($id): string
7 years ago
{
3 years ago
if (!$page = $this->pages->find($id)) {
7 years ago
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->render('view', [
'page' => $page,
]);
}
3 years ago
/**
* @param $id
* @param string $language
* @return string
* @throws NotFoundHttpException
*/
public function actionPreview($id, string $language = ''): string
{
3 years ago
if (!$page = $this->pages->findPreview($id, $language)) {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->render('view', [
'page' => $page,
]);
}
7 years ago
}