<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use SuperGear\Directus\Controllers\ControllerAbstract;
|
|
use SuperGear\Repositories\Manager;
|
|
|
|
/**
|
|
* controller for page items from directus
|
|
*
|
|
*
|
|
*
|
|
* @author Björn Hase
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://gitlab.tentakelfabrik.de/super-gear/directus GitHub Repository
|
|
*
|
|
*/
|
|
class PageController extends ControllerAbstract
|
|
{
|
|
/** slug for home */
|
|
const HOME_SLUG = 'home';
|
|
|
|
/** default view */
|
|
protected $defaultView = 'page/default';
|
|
|
|
/**
|
|
* get home page from slug
|
|
*
|
|
*
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$repository = Manager::get('Page');
|
|
$page = $repository->findOneBySlug(self::HOME_SLUG);
|
|
|
|
if ($this->notFound($page)) {
|
|
$this->app->redirect('404');
|
|
}
|
|
|
|
$this->render($page);
|
|
}
|
|
|
|
/**
|
|
* get single page from slug
|
|
*
|
|
*
|
|
* @param string $slug
|
|
*/
|
|
public function getAction($slug)
|
|
{
|
|
$repository = Manager::get('Page');
|
|
$page = $repository->findOneBySlug($slug);
|
|
|
|
if ($this->notFound($page)) {
|
|
$this->app->redirect('404');
|
|
}
|
|
|
|
$this->render($page);
|
|
}
|
|
|
|
/**
|
|
* if page not found
|
|
*
|
|
*/
|
|
public function notFoundAction()
|
|
{
|
|
$page = [
|
|
'data' => [
|
|
'view' => 'page/404'
|
|
]
|
|
];
|
|
|
|
$this->render($page);
|
|
}
|
|
}
|