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.

75 lines
1.4 KiB

5 years ago
  1. <?php
  2. namespace App\Controllers;
  3. use SuperGear\Directus\Controllers\ControllerAbstract;
  4. use SuperGear\Repositories\Manager;
  5. /**
  6. * controller for page items from directus
  7. *
  8. *
  9. *
  10. * @author Björn Hase
  11. * @license http://opensource.org/licenses/MIT The MIT License
  12. * @link https://gitlab.tentakelfabrik.de/super-gear/directus GitHub Repository
  13. *
  14. */
  15. class PageController extends ControllerAbstract
  16. {
  17. /** slug for home */
  18. const HOME_SLUG = 'home';
  19. /** default view */
  20. protected $defaultView = 'page/default';
  21. /**
  22. * get home page from slug
  23. *
  24. *
  25. */
  26. public function indexAction()
  27. {
  28. $repository = Manager::get('Page');
  29. $page = $repository->findOneBySlug(self::HOME_SLUG);
  30. if ($this->notFound($page)) {
  31. $this->app->redirect('404');
  32. }
  33. $this->render($page);
  34. }
  35. /**
  36. * get single page from slug
  37. *
  38. *
  39. * @param string $slug
  40. */
  41. public function getAction($slug)
  42. {
  43. $repository = Manager::get('Page');
  44. $page = $repository->findOneBySlug($slug);
  45. if ($this->notFound($page)) {
  46. $this->app->redirect('404');
  47. }
  48. $this->render($page);
  49. }
  50. /**
  51. * if page not found
  52. *
  53. */
  54. public function notFoundAction()
  55. {
  56. $page = [
  57. 'data' => [
  58. 'view' => 'page/404'
  59. ]
  60. ];
  61. $this->render($page);
  62. }
  63. }