PagesController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Static content controller.
  4. *
  5. * This file will render views from views/pages/
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @since 0.2.9
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace TestApp\Controller;
  20. use Cake\Core\Configure;
  21. use Cake\Network\Exception\NotFoundException;
  22. use Cake\Utility\Inflector;
  23. use Cake\View\Exception\MissingTemplateException;
  24. /**
  25. * Static content controller
  26. *
  27. * Override this controller by placing a copy in controllers directory of an application
  28. *
  29. * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
  30. */
  31. class PagesController extends AppController
  32. {
  33. /**
  34. * Default helper
  35. *
  36. * @var array
  37. */
  38. public $helpers = ['Html'];
  39. /**
  40. * Displays a view
  41. *
  42. * @param mixed What page to display
  43. * @return void
  44. * @throws Cake\Network\Exception\NotFoundException When the view file could not be found
  45. * or Cake\View\Exception\MissingTemplateException in debug mode.
  46. */
  47. public function display()
  48. {
  49. $path = func_get_args();
  50. $count = count($path);
  51. if (!$count) {
  52. return $this->redirect('/');
  53. }
  54. $page = $subpage = $titleForLayout = null;
  55. if (!empty($path[0])) {
  56. $page = $path[0];
  57. }
  58. if (!empty($path[1])) {
  59. $subpage = $path[1];
  60. }
  61. if (!empty($path[$count - 1])) {
  62. $titleForLayout = Inflector::humanize($path[$count - 1]);
  63. }
  64. $this->set([
  65. 'page' => $page,
  66. 'subpage' => $subpage,
  67. 'title_for_layout' => $titleForLayout
  68. ]);
  69. try {
  70. $this->render(implode('/', $path));
  71. } catch (MissingTemplateException $e) {
  72. if (Configure::read('debug')) {
  73. throw $e;
  74. }
  75. throw new NotFoundException();
  76. }
  77. }
  78. }