PagesController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. class PagesController extends AppController
  28. {
  29. /**
  30. * Default helper
  31. *
  32. * @var array
  33. */
  34. public $helpers = ['Html'];
  35. /**
  36. * Displays a view
  37. *
  38. * @param mixed What page to display
  39. * @return \Cake\Http\Response|null
  40. * @throws \Cake\Http\Exception\NotFoundException When the view file could not be found
  41. * or Cake\View\Exception\MissingTemplateException in debug mode.
  42. */
  43. public function display()
  44. {
  45. $path = func_get_args();
  46. $count = count($path);
  47. if (!$count) {
  48. return $this->redirect('/');
  49. }
  50. $page = $subpage = $titleForLayout = null;
  51. if (!empty($path[0])) {
  52. $page = $path[0];
  53. }
  54. if (!empty($path[1])) {
  55. $subpage = $path[1];
  56. }
  57. if (!empty($path[$count - 1])) {
  58. $titleForLayout = Inflector::humanize($path[$count - 1]);
  59. }
  60. $this->set([
  61. 'page' => $page,
  62. 'subpage' => $subpage,
  63. 'title_for_layout' => $titleForLayout,
  64. ]);
  65. try {
  66. $this->render(implode('/', $path));
  67. } catch (MissingTemplateException $e) {
  68. if (Configure::read('debug')) {
  69. throw $e;
  70. }
  71. throw new NotFoundException();
  72. }
  73. }
  74. }