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.

57 lines
1.2 KiB

3 years ago
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. 'slug' => '404',
  23. 'view' => 'page/404'
  24. ]
  25. ];
  26. /**
  27. * get single page from slug
  28. *
  29. *
  30. * @param string $slug
  31. */
  32. public function getAction($slug = NULL)
  33. {
  34. $repository = Manager::get('Page');
  35. $page = $repository->findOneBySlug($slug);
  36. if (count($page['data']) === 0) {
  37. $this->app->redirect('/404', 301);
  38. } else {
  39. $this->render($page);
  40. }
  41. }
  42. /**
  43. * if page not found
  44. *
  45. */
  46. public function notFoundAction()
  47. {
  48. $this->render($this->page404);
  49. }
  50. }