PagesController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Static content controller.
  4. *
  5. * This file will render views from views/pages/
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  15. * @link https://cakephp.org CakePHP(tm) Project
  16. * @since 0.2.9
  17. * @license https://opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace TestApp\Controller;
  20. use Cake\Core\Configure;
  21. use Cake\Http\Exception\NotFoundException;
  22. use Cake\Utility\Inflector;
  23. use Cake\View\Exception\MissingTemplateException;
  24. /**
  25. * Static content controller
  26. *
  27. */
  28. class PagesController extends AppController
  29. {
  30. /**
  31. * Default helper
  32. *
  33. * @var array
  34. */
  35. public $helpers = ['Html'];
  36. /**
  37. * Displays a view
  38. *
  39. * @param mixed What page to display
  40. * @return \Cake\Http\Response|null
  41. * @throws \Cake\Http\Exception\NotFoundException When the view file could not be found
  42. * or Cake\View\Exception\MissingTemplateException in debug mode.
  43. */
  44. public function display()
  45. {
  46. $path = func_get_args();
  47. $count = count($path);
  48. if (!$count) {
  49. return $this->redirect('/');
  50. }
  51. $page = $subpage = $titleForLayout = null;
  52. if (!empty($path[0])) {
  53. $page = $path[0];
  54. }
  55. if (!empty($path[1])) {
  56. $subpage = $path[1];
  57. }
  58. if (!empty($path[$count - 1])) {
  59. $titleForLayout = Inflector::humanize($path[$count - 1]);
  60. }
  61. $this->set([
  62. 'page' => $page,
  63. 'subpage' => $subpage,
  64. 'title_for_layout' => $titleForLayout,
  65. ]);
  66. try {
  67. $this->render(implode('/', $path));
  68. } catch (MissingTemplateException $e) {
  69. if (Configure::read('debug')) {
  70. throw $e;
  71. }
  72. throw new NotFoundException();
  73. }
  74. }
  75. }