Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
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.

56 lines
1.1 KiB

3 years ago
  1. <?php
  2. namespace App\Controllers;
  3. use App\Controllers\DirectusControllerAbstract;
  4. use App\Repositories\Manager;
  5. /**
  6. * controller for page items from directus
  7. *
  8. *
  9. * @author Björn Hase, Tentakelfabrik
  10. * @license http://opensource.org/licenses/MIT The MIT License
  11. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
  12. *
  13. */
  14. class PageController extends DirectusControllerAbstract
  15. {
  16. /** default view */
  17. protected $defaultView = 'page/default';
  18. /** 404 */
  19. protected $page404 = [
  20. 'data' => [
  21. 'title' => '404',
  22. 'view' => 'page/404'
  23. ]
  24. ];
  25. /**
  26. * get single page from slug
  27. *
  28. *
  29. * @param string $slug
  30. */
  31. public function getAction($slug = NULL)
  32. {
  33. $repository = Manager::get('Page');
  34. $page = $repository->findOneBySlug($slug);
  35. if (count($page['data']) === 0) {
  36. $this->app->redirect('/404', 301);
  37. } else {
  38. $this->render($page);
  39. }
  40. }
  41. /**
  42. * if page not found
  43. *
  44. */
  45. public function notFoundAction()
  46. {
  47. $this->render($this->page404);
  48. }
  49. }