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.
		
		
		
		
			
				
					60 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					60 lines
				
				1.2 KiB
			| 
								 
											8 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace frontend\controllers;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use core\repositories\page\read\PageReadRepository;
							 | 
						||
| 
								 | 
							
								use yii\web\Controller;
							 | 
						||
| 
								 | 
							
								use yii\web\NotFoundHttpException;
							 | 
						||
| 
								 | 
							
								use yii\filters\AccessControl;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * PagesController implements the CRUD actions for Page model.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								class PageController extends Controller
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    private $pages;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function __construct($id, $module, PageReadRepository $pages, $config = [])
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        parent::__construct($id, $module, $config);
							 | 
						||
| 
								 | 
							
								        $this->pages = $pages;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function behaviors(): array
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return [
							 | 
						||
| 
								 | 
							
											'access' => [
							 | 
						||
| 
								 | 
							
												'class' => AccessControl::className(),
							 | 
						||
| 
								 | 
							
												'rules' => [
							 | 
						||
| 
								 | 
							
													[
							 | 
						||
| 
								 | 
							
														'actions' => ['view'],
							 | 
						||
| 
								 | 
							
														'allow' => true,
							 | 
						||
| 
								 | 
							
														'roles' => ['Pages'],
							 | 
						||
| 
								 | 
							
													],
							 | 
						||
| 
								 | 
							
													[    // all the action are accessible to admin
							 | 
						||
| 
								 | 
							
														'allow' => true,
							 | 
						||
| 
								 | 
							
														'roles' => ['admin'],
							 | 
						||
| 
								 | 
							
													],
							 | 
						||
| 
								 | 
							
												],
							 | 
						||
| 
								 | 
							
											],
							 | 
						||
| 
								 | 
							
										];
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * @param $id
							 | 
						||
| 
								 | 
							
								     * @return mixed
							 | 
						||
| 
								 | 
							
								     * @throws NotFoundHttpException
							 | 
						||
| 
								 | 
							
								     * @internal param string $slug
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function actionView($id)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        if (!$page = $this->pages->find($id)) {
							 | 
						||
| 
								 | 
							
								            throw new NotFoundHttpException('The requested page does not exist.');
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        return $this->render('view', [
							 | 
						||
| 
								 | 
							
								            'page' => $page,
							 | 
						||
| 
								 | 
							
								        ]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |