PagesController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Static content controller.
  4. *
  5. * This file will render views from views/pages/
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * For full copyright and license information, please see the LICENSE.txt
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  17. * @link http://cakephp.org CakePHP(tm) Project
  18. * @package Cake.Controller
  19. * @since CakePHP(tm) v 0.2.9
  20. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  21. */
  22. App::uses('AppController', 'Controller');
  23. /**
  24. * Static content controller
  25. *
  26. * Override this controller by placing a copy in controllers directory of an application
  27. *
  28. * @package Cake.Controller
  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. * This controller does not use a model
  40. *
  41. * @var array
  42. */
  43. public $uses = array();
  44. /**
  45. * Displays a view
  46. *
  47. * @param mixed What page to display
  48. * @return void
  49. * @throws NotFoundException When the view file could not be found
  50. * or MissingViewException in debug mode.
  51. */
  52. public function display() {
  53. $path = func_get_args();
  54. $count = count($path);
  55. if (!$count) {
  56. return $this->redirect('/');
  57. }
  58. $page = $subpage = $titleForLayout = null;
  59. if (!empty($path[0])) {
  60. $page = $path[0];
  61. }
  62. if (!empty($path[1])) {
  63. $subpage = $path[1];
  64. }
  65. if (!empty($path[$count - 1])) {
  66. $titleForLayout = Inflector::humanize($path[$count - 1]);
  67. }
  68. $this->set(array(
  69. 'page' => $page,
  70. 'subpage' => $subpage,
  71. 'title_for_layout' => $titleForLayout
  72. ));
  73. try {
  74. $this->render(implode('/', $path));
  75. } catch (MissingViewException $e) {
  76. if (Configure::read('debug')) {
  77. throw $e;
  78. }
  79. throw new NotFoundException();
  80. }
  81. }
  82. }