PagesController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 CakePHP(tm) v 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\Error;
  22. use Cake\Utility\Inflector;
  23. /**
  24. * Static content controller
  25. *
  26. * Override this controller by placing a copy in controllers directory of an application
  27. *
  28. * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
  29. */
  30. class PagesController extends AppController {
  31. /**
  32. * Default helper
  33. *
  34. * @var array
  35. */
  36. public $helpers = array('Html', 'Session');
  37. /**
  38. * This controller does not use a model
  39. *
  40. * @var array
  41. */
  42. public $uses = array();
  43. /**
  44. * Displays a view
  45. *
  46. * @param mixed What page to display
  47. * @return void
  48. * @throws \Cake\Error\NotFoundException When the view file could not be found.
  49. * @throws \Cake\Error\MissingViewException in debug mode.
  50. */
  51. public function display() {
  52. $path = func_get_args();
  53. $count = count($path);
  54. if (!$count) {
  55. return $this->redirect('/');
  56. }
  57. $page = $subpage = $titleForLayout = null;
  58. if (!empty($path[0])) {
  59. $page = $path[0];
  60. }
  61. if (!empty($path[1])) {
  62. $subpage = $path[1];
  63. }
  64. if (!empty($path[$count - 1])) {
  65. $titleForLayout = Inflector::humanize($path[$count - 1]);
  66. }
  67. $this->set(array(
  68. 'page' => $page,
  69. 'subpage' => $subpage,
  70. 'title_for_layout' => $titleForLayout
  71. ));
  72. try {
  73. $this->render(implode('/', $path));
  74. } catch (Error\MissingViewException $e) {
  75. if (Configure::read('debug')) {
  76. throw $e;
  77. }
  78. throw new Error\NotFoundException();
  79. }
  80. }
  81. }