PagesController.php 2.1 KB

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