PagesController.php 2.1 KB

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